"Do it for the gram." - me
protein_value fat_value carbohydrate_value
0 3.47 8.37 4.07
1 4.27 8.79 3.87
2 2.44 8.37 3.57
3 2.44 8.37 3.57
4 2.44 8.37 3.57
.. ... ... ...
307 2.44 8.37 3.57
308 2.44 8.37 3.57
309 2.44 8.37 3.57
310 2.44 8.37 3.57
311 2.44 8.37 3.57
[312 rows x 3 columns]
df['fat_value'] = df['fat_value'] / 9
df['carbohydrate_value'] = df['carbohydrate_value'] / 4
df['protein_value'] = df['protein_value'] / 4
print(df[:5])
protein_value fat_value carbohydrate_value
0 0.216875 0.103333 0.254375
1 0.266875 0.108519 0.241875
2 0.152500 0.103333 0.223125
3 0.152500 0.103333 0.223125
4 0.152500 0.103333 0.223125
2022_x 2022_y
0 33300.838819 74.992000
1 1642.432039 62.899031
2 352.603733 62.879000
3 1788.875347 57.626176
4 2933.484644 61.929000
.. ... ...
260 3745.560367 72.598000
261 5290.977397 79.524000
263 6766.481254 61.480000
264 1456.901570 61.803000
265 1676.821489 59.391000
# prompt: sklearn linear regression over dataframe "both"
from sklearn.linear_model import LinearRegression
# Prepare the data for linear regression
X = both[['2022_x']] # GDP per capita in 2022
y = both['2022_y'] # Life expectancy in 2022
# Create and train the linear regression model
model = LinearRegression()
model.fit(X, y)
# Print the model coefficients
print("Coefficients:", model.coef_)
print("Intercept:", model.intercept_)
Coefficients: [0.00019047]
Intercept: 68.69969966270624
# prompt: do polynomial regression of degree 3 over both
# Create polynomial features up to degree 3
from sklearn.preprocessing import PolynomialFeatures
poly = PolynomialFeatures(degree=3)
X_poly = poly.fit_transform(X)
# Create and train the polynomial regression model
model_poly = LinearRegression()
model_poly.fit(X_poly, y)
# Print the model coefficients
print("Polynomial Coefficients:", model_poly.coef_)
print("Polynomial Intercept:", model_poly.intercept_)
Polynomial Coefficients: [ 0.00000000e+00 7.16975595e-04 -8.57111644e-09 2.87583542e-14]
Polynomial Intercept: 65.12557554366506
Coefficients: [4.54777158]
Intercept: 31.58450749077179