我目前正在爲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