Multinomial_Regression
#!/usr/bin/env python
# coding: utf-8
# In[39]:
#import the necessary libraries
from sklearn import datasets
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import accuracy_score
# In[40]:
#load the digit datasets
digits=datasets.load_digits()
# In[41]:
#defining feature matrix x and response vecoor y
X=digits.data
y=digits.target
print(X)
print(y)
# In[48]:
#split the test train data
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=1)
print(y_test)
# In[49]:
#standradize features using standardscaler
scaler=StandardScaler()
scaler.fit(X_train)
X_train_scaled=scaler.transform(X_train)
X_test_scaled=scaler.transform(X_test)
# In[50]:
#create the logistic regression model
model=LogisticRegression()
# In[51]:
#train the model on scaled training data
model.fit(X_train_scaled,y_train)
# In[52]:
#make predidction on the sclaed testing data
y_pred=model.predict(X_test_scaled)
print(y_pred)
# In[53]:
#evaluate model performance
acc=accuracy_score(y_test,y_pred)
print("Logistic Regression model accuarcy (in %):",acc*100)
# In[ ]:
# In[ ]:
Comments
Post a Comment