ฉันกำลังพยายามทำการถดถอยเชิงเส้นอย่างง่ายในหลามโดยตัวแปร x คือการนับจำนวนคำของคำอธิบายโครงการและค่า y คือความเร็วในการระดมทุนในหน่วยวัน
ฉันสับสนเล็กน้อยเนื่องจากค่าความผิดพลาดรูทเฉลี่ยกำลังสอง (RMSE) คือ 13.77 สำหรับการทดสอบและ 13.88 สำหรับข้อมูลการฝึกอบรม อันดับแรก RMSE ไม่ควรอยู่ระหว่าง 0 ถึง 1 ใช่หรือไม่ และประการที่สอง RMSE สำหรับข้อมูลการทดสอบไม่ควรสูงกว่าข้อมูลการฝึกอบรมใช่หรือไม่ ดังนั้นฉันเดาว่าฉันทำอะไรผิด แต่ไม่แน่ใจว่าผิดตรงไหน
นอกจากนี้ ฉันจำเป็นต้องทราบค่าสัมประสิทธิ์น้ำหนักสำหรับการถดถอย แต่น่าเสียดายที่ไม่ทราบวิธีพิมพ์เนื่องจากมันถูกซ่อนอยู่ในวิธี sklearn ใครสามารถช่วยออกที่นี่?
นี่คือสิ่งที่ฉันมีจนถึงตอนนี้:
import numpy as np
import matplotlib.pyplot as plt
import sqlite3
from sklearn.model_selection import train_test_split
from sklearn import linear_model
con = sqlite3.connect('database.db')
cur = con.cursor()
# y-variable in regression is funding speed ("DAYS_NEEDED")
cur.execute("SELECT DAYS_NEEDED FROM success")
y = cur.fetchall() # list of tuples
y = np.array([i[0] for i in y]) # list of int # y.shape = (1324476,)
# x-variable in regression is the project description length ("WORD_COUNT")
cur.execute("SELECT WORD_COUNT FROM success")
x = cur.fetchall()
x = np.array([i[0] for i in x]) # list of int # x.shape = (1324476,)
# Get the train and test data split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42)
# Fit a model
lm = linear_model.LinearRegression()
x_train = x_train.reshape(-1, 1) # new shape: (1059580, 1)
y_train = y_train.reshape(-1, 1) # new shape: (1059580, 1)
model = lm.fit(x_train, y_train)
x_test = x_test.reshape(-1, 1) # new shape: (264896, 1)
predictions_test = lm.predict(x_test)
predictions_train = lm.predict(x_train)
print("y_test[5]: ", y_test[5]) # 14
print("predictions[5]: ", predictions_test[5]) # [ 12.6254537]
# Calculate the root mean square error (RMSE) for test and training data
N = len(y_test)
rmse_test = np.sqrt(np.sum((np.array(y_test).flatten() - np.array(predictions_test).flatten())**2)/N)
print("RMSE TEST: ", rmse_test) # 13.770731326
N = len(y_train)
rmse_train = np.sqrt(np.sum((np.array(y_train).flatten() - np.array(predictions_train).flatten())**2)/N)
print("RMSE train: ", rmse_train) # 13.8817814595
ความช่วยเหลือใด ๆ ที่ชื่นชมมาก! ขอบคุณ!
model.coef_
และmodel.intercept_
- person Umang Gupta   schedule 27.06.2018y
) อยู่ระหว่าง 0 ถึง 1 และ ค่าที่คาดการณ์ไว้ทั้งหมดอยู่ระหว่าง 0 ถึง 1 ด้วย RMSE ของข้อมูลทดสอบจะ ใกล้เคียงมากขึ้น ไปที่การฝึกอบรม RMSE (และต่ำกว่า) หากคุณมีโมเดลที่ได้รับการฝึกอบรมมาเป็นอย่างดี มันจะสูงขึ้นหากคุณมีโมเดลที่พอดีเกินไป อาจต่ำกว่านี้หากข้อมูลการทดสอบของคุณง่ายเกินไปสำหรับโมเดล คุณอาจพบว่าสิ่งนี้มีประโยชน์ - person Autonomous   schedule 27.06.2018