└── regression /regression: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import pandas as pd 3 | import matplotlib.pyplot as plt 4 | df=pd.read_csv('D:\\Jeyashri\\IBM\\Datasets\\head1.csv') 5 | df.head(10) 6 | plt.scatter(df.HeadSize,df.BrainWeight,color='red') 7 | plt.xlabel("HeadSize") 8 | plt.ylabel("BrainWeight") 9 | plt.show() 10 | from sklearn.model_selection import train_test_split 11 | from sklearn.linear_model import LogisticRegression 12 | from sklearn.metrics import confusion_matrix, accuracy_score 13 | x = df.drop ('Gender', axis = 1) 14 | y = df ['Gender'] 15 | x_train, x_test, y_train, y_test = train_test_split (x, y, test_size = 0.33, random_state = 1) 16 | logmodel = LogisticRegression () 17 | logmodel.fit (x_train, y_train) 18 | predict= logmodel.predict (x_test) 19 | print (confusion_matrix (y_test, predict)) 20 | print (accuracy_score (y_test, predict)) 21 | predict 22 | from sklearn.metrics import classification_report 23 | classification_report(y_test,predict) 24 | from sklearn.metrics import accuracy_score 25 | accuracy_score(y_test,predict) 26 | plt.figure(figsize=(12, 6)) 27 | plt.plot(x_test,y,'ro')# regression line 28 | plt.plot(predict,y_test) # scatter plot showing actual data 29 | plt.title('Actual vs Predicted') 30 | plt.xlabel('X') 31 | plt.ylabel('y') 32 | plt.show() 33 | --------------------------------------------------------------------------------