Binomial_Regression
#!/usr/bin/env python
# coding: utf-8
# In[16]:
#import the necessary libraries
from sklearn.datasets import load_breast_cancer
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[2]:
#load breast cancer dataset
X,y=load_breast_cancer(return_X_y=True)
# In[3]:
#split the test train data
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.20,random_state=42)
print(y_test)
# In[5]:
#standardize features using standardscaler
scaler=StandardScaler()
scaler.fit(X_train)
X_train_scaled=scaler.transform(X_train)
X_test_scaled=scaler.transform(X_test)
# In[6]:
#create the logistic regression model
model=LogisticRegression()
# In[7]:
#train the model on scaled training data
model.fit(X_train_scaled,y_train)
# In[18]:
#make predidction on the sclaed testing data
y_pred=model.predict(X_test_scaled)
print(y_pred)
# In[19]:
#evaluate model performance
acc=accuracy_score(y_test,y_pred)
print("Logistic Regression model accuarcy (in %):",acc*100)
# In[ ]:
Comments
Post a Comment