1
\$\begingroup\$

I am a newcomer in Machine Learning and I have wrote a simple program for logistic regression based on Iris dataset.

I would like for experts to tell me about its drawbacks and bugs, and if it can be implemented in easier ways.

#Loading data
import pandas as pd
df=pd.read_csv('file:///C:/Users/Desktop/iris.csv')
dftr=pd.read_csv('file:///C:/Users/Desktop/AI/iristr.csv')
dfts=pd.read_csv('file:///C:/Users/Desktop/AI/irists.csv')

#Normalizing data
from sklearn import preprocessing
from sklearn.preprocessing import StandardScaler
dfr=df.drop(df.columns[len(df.columns)-1], axis=1)
dfr=preprocessing.StandardScaler().fit(dfr).transform(dfr)
dfr=pd.DataFrame(dfr)

#Splitting data
Xtr=dftr.iloc[:,0:4].dropna()
Xts=dfts.iloc[:,0:4].dropna()
Ytr=dftr.iloc[:,4].dropna()
Yts=dfts.iloc[:,4].dropna()

#Defining classifier
from sklearn.linear_model import LogisticRegression
clf = LogisticRegression(penalty='l2', tol=0.0001, C=1.0, intercept_scaling=1, solver='newton-cg', max_iter=100, warm_start=False)

#Training
M=clf.fit(Xtr, Ytr)

#Predicting
Ytrpr=M.predict(Xtr)
Ytspr=M.predict(Xts)

#evaluation
from sklearn.metrics import accuracy_score
ACtr=accuracy_score(Ytr, Ytrpr)
ACts=accuracy_score(Yts, Ytspr)
print('ACtr=', ACtr)
print('ACts=', ACts)
\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy