这是来自sklearn的普通最小二乘线性回归。线性_模块。 语法: 学习。线性模型。线性回归(拟合截距=True,标准化=False,复制X=True,n_作业=1):
null
参数:
安装截距: [布尔值,默认值为True]是否计算模型的截距。 正常化: [布尔值,默认值为False]回归前的归一化。 复印件X: [布尔值,默认值为True]如果为True,则复制X,否则将被覆盖。 n_工作: [int,默认值为1]如果使用了-1所有CPU。这将加快处理大型数据集的速度。
在给定的数据集中,给出了50家公司的研发支出、管理成本和营销支出以及获得的利润。本文的目标是建立一个ML模型,该模型能够在给定企业的研发费用、管理费用和营销费用的情况下预测企业的利润价值。 要下载数据集,请单击 在这里 .
代码: 利用线性回归预测公司利润
# Importing the libraries import numpy as np import pandas as pd # Importing the dataset print ( "Dataset.head() " , dataset.head()) # Input values x = dataset.iloc[:, : - 1 ].values print ( "First 10 Input Values : " , x[ 0 : 10 , :]) |
print ( "Dataset Info : " ) print (dataset.info()) |
# Input values x = dataset.iloc[:, : - 1 ].values print ( "First 10 Input Values : " , x[ 0 : 10 , :]) # Output values y = dataset.iloc[:, 3 ].values y1 = y y1 = y1.reshape( - 1 , 1 ) print ( "First 10 Output true value : " , y1[ 0 : 10 , :]) |
# Dividing input and output data to train and test data # Training : Testing = 80 : 20 from sklearn.cross_validation import train_test_split xtrain, xtest, ytrain, ytest = train_test_split(x, y, test_size = 0.2 , random_state = 0 ) # Feature Scaling # Multilinear regression takes care of Feature Scaling # So we need not do it manually # Fitting Multi Linear regression model to training model from sklearn.linear_model import LinearRegression regressor = LinearRegression() regressor.fit(xtrain, ytrain) # predicting the test set results y_pred = regressor.predict(xtest) y_pred1 = y_pred y_pred1 = y_pred1.reshape( - 1 , 1 ) print ( " RESULT OF LINEAR REGRESSION PREDICTION : " ) print ( "First 10 Predicted value : " , y_pred1[ 0 : 10 , :]) |
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END