I'd like to ask you a question about Python's multiple regression linear model.

Asked 2 years ago, Updated 2 years ago, 135 views

- This is a link to the regression model data csv file!

https://drive.google.com/file/d/1P1IAq7q-3u8C6CyQoFCiuCch9eh3bn60/view?usp=sharing

I'm making a regression model with this data, but I'm asking because I'm not sure because it's my first time with Python. According to this data, is it multiple regression because there are three x_0x_1x_2x? Or is it just a regression model? And in the case of multiple regression analysis, do we model the data right away without making it into visual data? I'm going to make a regression model with that data, so please give me some tips or teach me.

python machine-learning regression-analysis

2022-09-21 10:21

1 Answers

https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html

Study linear regression and look at the document above. For general machine learning, scikit-learn is simple and good. The document is well-written.

The simple linear regression example code is

import pandas as pd
from sklearn.linear_model import LinearRegression

# # read data and set X and y
df = pd.read_csv('test.csv')

print(df.info())
print(df.head())

X = df[['x_0', 'x_1', 'x_2']]
y = df['y']

# # regression using sklearn lin-reg model
reg = LinearRegression()
reg.fit(X, y)
print(reg.coef_)
print(reg.intercept_)

Execution result

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 200 entries, 0 to 199
Data columns (total 5 columns):
 #   #   Column      Non-Null Count  Dtype
---  ------      --------------  -----
 0   Unnamed: 0  200 non-null    int64
 1   x_0         200 non-null    float64
 2   x_1         200 non-null    float64
 3   x_2         200 non-null    float64
 4   y           200 non-null    float64
dtypes: float64(4), int64(1)
memory usage: 7.9 KB
None
   Unnamed: 0       x_0       x_1       x_2          y
0           0 -1.774915  0.627609  0.320547  44.371864
1           1 -0.433889 -0.271014 -0.726314 -52.123380
2           2 -2.132202 -0.329896  2.034855   5.649362
3           3 -2.368874  0.282574 -1.004728 -41.428106
4           4  1.089158  0.624181 -0.427276  61.875930
[16.38626013 92.78638947 33.74001825]
4.139570957198153


2022-09-21 10:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.