【发布时间】:2016-05-23 13:10:18
【问题描述】:
我目前正在为 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中的数据样本?
-
如果只打印价格,则:[u'B']
-
drive.google.com/open?id=0BzvrBlV2c5P-bGt4VG85emNnbXc 这是 xlsx 文件。而对于 42491,只是一个日期值。我发现我使用的代码无法解析 xlsx 中的日期格式
标签: python machine-learning logistic-regression