【问题标题】:Medical insurance cost prediction using Linear regression使用线性回归的医疗保险成本预测
【发布时间】: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


【解决方案1】:

我认为你做得很好。但是,您可以使用常用比率来拆分训练和测试集,而不是使用随机(用于拆分数据)。通常是 80:20、75:25 (train:test)。

如果你使用像训练测试分割这样的基本分割,你只能得到一个结果。下次尝试学习 k-Fold 交叉验证来分割数据。

【讨论】:

  • 非常感谢您的建议,我将尝试 K-fold 交叉验证方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多