|
import pandas |
|
import sklearn |
|
from sklearn.linear_model import LogisticRegression |
|
from sklearn.model_selection import train_test_split |
|
from sklearn.metrics import accuracy_score |
|
from sklearn.metrics import confusion_matrix |
|
|
|
|
|
df = pandas.read_csv('RSL_copy.csv') |
|
print(df.dtypes) |
|
data= df.values |
|
|
|
|
|
X_array = data[:,0:2] |
|
Y_array = data[:,2] |
|
|
|
|
|
|
|
X_train, X_test, y_train, y_test = train_test_split(X_array,Y_array,test_size=0.2) |
|
|
|
|
|
lrmodel=LogisticRegression(solver='newton-cg') |
|
|
|
lrmodel.fit(X_train,y_train) |
|
|
|
train_prediction = lrmodel.predict(X_train) |
|
|
|
|
|
accuracy = accuracy_score(train_prediction,y_train) |
|
print('train prediction is',accuracy*100,'%') |
|
|
|
|
|
prediction =lrmodel.predict(X_test) |
|
|
|
accuracy = accuracy_score(prediction,y_test) |
|
print('test predcition:', accuracy*100,'%') |
|
|
|
|
|
confusion_matrix(y_test,prediction) |
|
print(confusion_matrix(y_test,prediction)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
import pickle |
|
filename = 'MWmodel.sav' |
|
pickle.dump(lrmodel,open(filename, 'wb')) |
|
|