私は数時間この状態にいて、今実際にはまったように感じています。Pythonロジスティック回帰
私は、csv "ScoreBuckets.csv"に列の束を使用して、その "SCore_Bucket"というcsvの別の列を予測しようとしています。私はcsvで複数の列を使用して、Score_Bucket列を予測したいと考えています。私が抱えている問題は、私の結果がまったく意味をなさないということで、複数の列を使用してScore_Bucket列を予測する方法がわかりません。私はデータマイニングに新しいので、私は100%コード/構文に精通していません。
import pandas as pd
import numpy as np
from sklearn import metrics
from sklearn.linear_model import LogisticRegression
from sklearn.cross_validation import KFold, cross_val_score
dataset = pd.read_csv('ScoreBuckets.csv')
CV = (dataset.Score_Bucket.reshape((len(dataset.Score_Bucket), 1))).ravel()
data = (dataset.ix[:,'CourseLoad_RelativeStudy':'Sleep_Sex'].values).reshape(
(len(dataset.Score_Bucket), 2))
# Create a KNN object
LogReg = LogisticRegression()
# Train the model using the training sets
LogReg.fit(data, CV)
# the model
print('Coefficients (m): \n', LogReg.coef_)
print('Intercept (b): \n', LogReg.intercept_)
#predict the class for each data point
predicted = LogReg.predict(data)
print("Predictions: \n", np.array([predicted]).T)
# predict the probability/likelihood of the prediction
print("Probability of prediction: \n",LogReg.predict_proba(data))
modelAccuracy = LogReg.score(data,CV)
print("Accuracy score for the model: \n", LogReg.score(data,CV))
print(metrics.confusion_matrix(CV, predicted, labels=["Yes","No"]))
# Calculating 5 fold cross validation results
LogReg = LogisticRegression()
kf = KFold(len(CV), n_folds=5)
scores = cross_val_score(LogReg, data, CV, cv=kf)
print("Accuracy of every fold in 5 fold cross validation: ", abs(scores))
print("Mean of the 5 fold cross-validation: %0.2f" % abs(scores.mean()))
print("The accuracy difference between model and KFold is: ",
abs(abs(scores.mean())-modelAccuracy))
ScoreBuckets.csv:
Score_Bucket,Healthy,Course_Load,Miss_Class,Relative_Study,Faculty,Sleep,Relation_Status,Sex,Relative_Stress,Res_Gym?,Tuition_Awareness,Satisfaction,Healthy_TuitionAwareness,Healthy_TuitionAwareness_MissClass,Healthy_MissClass_Sex,Sleep_Faculty_RelativeStress,TuitionAwareness_ResGym,CourseLoad_RelativeStudy,Sleep_Sex
5,0.5,1,0,1,0.4,0.33,1,0,0.5,1,0,0,0.75,0.5,0.17,0.41,0.5,1,0.17
2,1,1,0.33,0.5,0.4,0.33,0,0,1,0,0,0,0.5,0.44,0.44,0.58,0,0.75,0.17
5,0.5,1,0,0.5,0.4,0.33,1,0,0.5,0,1,0,0.75,0.5,0.17,0.41,0.5,0.75,0.17
4,0.5,1,0,0,0.4,0.33,0,0,0.5,0,1,0,0.25,0.17,0.17,0.41,0.5,0.5,0.17
5,0.5,1,0.33,0.5,0.4,0,1,1,1,0,1,0,0.75,0.61,0.61,0.47,0.5,0.75,0.5
5,0.5,1,0,1,0.4,0.33,1,1,1,1,1,1,0.75,0.5,0.5,0.58,1,1,0.67
5,0.5,1,0,0,0.4,0.33,0,0,0.5,0,1,0,0.25,0.17,0.17,0.41,0.5,0.5,0.17
2,0.5,1,0.67,0.5,0.4,0,1,1,0.5,0,0,0,0.75,0.72,0.72,0.3,0,0.75,0.5
5,0.5,1,0,1,0.4,0.33,0,1,1,0,1,1,0.25,0.17,0.5,0.58,0.5,1,0.67
5,1,1,0,0.5,0.4,0.33,0,1,0.5,0,1,1,0.5,0.33,0.67,0.41,0.5,0.75,0.67
0,0.5,1,0,1,0.4,0.33,0,0,0.5,0,0,0,0.25,0.17,0.17,0.41,0,1,0.17
2,0.5,1,0,0.5,0.4,0.33,1,1,1,0,0,0,0.75,0.5,0.5,0.58,0,0.75,0.67
5,0.5,1,0,1,0.4,0.33,0,0,1,1,1,0,0.25,0.17,0.17,0.58,1,1,0.17
0,0.5,1,0.33,0.5,0.4,0.33,1,1,0.5,0,1,0,0.75,0.61,0.61,0.41,0.5,0.75,0.67
5,0.5,1,0,0.5,0.4,0.33,0,0,0.5,0,1,1,0.25,0.17,0.17,0.41,0.5,0.75,0.17
4,0,1,0.67,0.5,0.4,0.67,1,0,0.5,1,0,0,0.5,0.56,0.22,0.52,0.5,0.75,0.34
2,0.5,1,0.33,1,0.4,0.33,0,0,0.5,0,1,0,0.25,0.28,0.28,0.41,0.5,1,0.17
5,0.5,1,0.33,0.5,0.4,0.33,0,1,1,0,1,0,0.25,0.28,0.61,0.58,0.5,0.75,0.67
5,0.5,1,0,1,0.4,0.33,0,0,0.5,1,1,0,0.25,0.17,0.17,0.41,1,1,0.17
5,0.5,1,0.33,0.5,0.4,0.33,1,1,1,0,1,0,0.75,0.61,0.61,0.58,0.5,0.75,0.67
出力:
Coefficients (m):
[[-0.4012899 -0.51699939]
[-0.72785212 -0.55622303]
[-0.62116232 0.30564259]
[ 0.04222459 -0.01672418]]
Intercept (b):
[-1.80383738 -1.5156701 -1.29452772 0.67672118]
Predictions:
[[5]
[5]
[5]
[5]
...
[5]
[5]
[5]
[5]]
Probability of prediction:
[[ 0.09302973 0.08929139 0.13621146 0.68146742]
[ 0.09777325 0.10103782 0.14934111 0.65184782]
[ 0.09777325 0.10103782 0.14934111 0.65184782]
[ 0.10232068 0.11359509 0.16267645 0.62140778]
...
[ 0.07920945 0.08045552 0.17396476 0.66637027]
[ 0.07920945 0.08045552 0.17396476 0.66637027]
[ 0.07920945 0.08045552 0.17396476 0.66637027]
[ 0.07346886 0.07417316 0.18264008 0.66971789]]
Accuracy score for the model:
0.671171171171
[[0 0]
[0 0]]
Accuracy of every fold in 5 fold cross validation:
[ 0.64444444 0.73333333 0.68181818 0.63636364 0.65909091]
Mean of the 5 fold cross-validation: 0.67
The accuracy difference between model and KFold is: 0.00016107016107
私は出力がないと言う理由でここ
は、私がこれまで持っているコードです。理にかなっている理由は2つあります。 1.カラムに入力するデータに関係なく、予測精度cyは同じままであり、Score_Buckets列のより良い予測子である列があるため、発生しないはずです。 2.カラムScore_Bucketsは、同じサイズでなければならないと言われているので、複数のカラムを使用することはできませんが、カラムScore_Bucketsだけよりも複数のカラムのサイズが明らかに大きい場合はどうでしょうか。
予測に間違いはありますか?
ありがとうございました。 Score_Bucket列を複数の列に分割し、各列を予測しようとします。上記のコードで、私はエラーを取得します:residual_error = CV - 予測しました。 ValueError:渡された項目の数が間違っている222、配置が1を意味する – user2997307
「Score_Bucket列を複数の列に分割する」という意味がわかりません。ターゲット 'y'は1つの列に残す必要があるため、複数の列に分割する必要はありません。さらに、残留誤差を計算しているので、実際に回帰をしたいと思う。これは分類子であるため、ロジスティック回帰ではできません。 – cbrnr