我目前正在为python进行机器学习中的Logistic回归。这是我写的代码。python中的逻辑回归
import pandas as pd
from sklearn import linear_model
import numpy as np
from sklearn.utils import column_or_1d
logistic = linear_model.LogisticRegression()
data = pd.read_excel('/home/mick/PycharmProjects/project1/excel/Ron95_Price_Class.xlsx')
X = data[['Date']]
y = data[['Ron95_RM']]
y = np.ravel(y)
logistic.fit(X, y)
price = logistic.predict(42491)
print "The price for Ron95 in next month will be RM", np.array_str(price,1)
这是代码
The price for Ron95 in next month will be RM [ u'B']
没有错误的输出,但我的问题是字符输出RM后应该是“B”或其它字符。我不知道是因为我错误地执行了代码还是只是numpy数组的格式问题。
因为我今天基本上刚刚开始使用Python,抱歉,如果我只是犯了一个愚蠢的错误。
什么是42491和打印价格的结果是什么 –
您可以给出xlsx中的数据样本吗? – DJanssens
如果只打印价格,那么:[u'B'] – Mick