【发布时间】:2021-03-10 08:03:45
【问题描述】:
我是机器学习的初学者。我对线性回归和逻辑回归有一些基本的了解。
作为将我迄今为止在线性回归中学到的概念应用的第一步,我尝试根据数据集中给出的特征来预测医疗保险费用。我使用多元回归进行预测。我的准确度得分为 0.79,但我对我的模型不满意,我想知道这种编码是否真的能帮助我成为机器学习专家。
我真的很想知道学习 ML 的理论和编码概念以成为专业人士的方法。我还想真正注意到我目前正在学习 Andrew Ng 在 coursera 平台上教授的机器学习课程.
我还需要知道如何可视化多元回归。
这是github文件夹的链接。
它包含数据集和python代码。
我的代码:
import pandas as pd
import matplotlib.pyplot as plt
df=pd.read_csv('insurance.csv')
#matrix of X features
X=df.iloc[:,:-1].values
#vector of prediction values
y=df.iloc[:,-1].values
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(X,y,random_state=0)
from sklearn.preprocessing import StandardScaler
sc=StandardScaler()
X_train[:,:]=sc.fit_transform(X_train[:,:])
X_test[:,:]=sc.fit_transform(X_test[:,:])
y_train=y_train.reshape(-1,1)
y_test=y_test.reshape(-1,1)
#y_train[:]=sc.fit_transform(y_train[:])
#y_test[:]=sc.fit_transform(y_test[:])
from sklearn.linear_model import LinearRegression
reg=LinearRegression()
reg.fit(X_train,y_train)
y_pred=reg.predict(X_test)
y_pred=y_pred.reshape(-1,1)
print(reg.score(X_test,y_test))
print("reg coefficents:")
print(reg.coef_)
print(reg.intercept_)
我的数据集包括以下列:
age: age of primary beneficiary
sex: insurance contractor gender, female, male
bmi: Body mass index, providing an understanding of body, weights that are relatively high or low relative to height,
objective index of body weight (kg / m ^ 2) using the ratio of height to weight, ideally 18.5 to 24.9
children: Number of children covered by health insurance / Number of dependents
smoker: Smoking
region: the beneficiary residential area in the US, northeast, southeast, southwest, northwest.
charges: Individual medical costs billed by health insurance
数据集链接(kaggle):https://www.kaggle.com/mirichoi0218/insurance
【问题讨论】:
-
欢迎来到 SO。请重新阅读 How to ask,因为您似乎在第一次阅读时错过了一些关键点,即“如果可以创建一个问题的现场示例您可以链接到 [...] 然后这样做 - 但也将代码复制到问题本身中。不是每个人都可以访问外部网站,并且链接可能会随着时间的推移而中断“(强调原文)。
-
我会更新帖子。感谢您的评论
标签: python matplotlib machine-learning linear-regression