栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

用python进行多元线性回归,对数据进行中心化和标准化

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

用python进行多元线性回归,对数据进行中心化和标准化

In regression analysis, if there are two or more independent variables, it is called multiple regression. In fact, a phenomenon is often associated with multiple factors. It is more effective and practical to predict or estimate the dependent variable by the optimal combination of multiple independent variables than to predict or estimate only one independent variable. Therefore, multivariate linear regression is more practical than univariate linear regression.

Multivariate linear regression is similar to univariate linear regression. The least square method can be used to estimate the model parameters, and the model and model parameters need to be statistically tested.

Data centralization is different from standardization. Centralization is to subtract the average from the original data, while standardization is to subtract the average from the original data and then divide it by the standard deviation. The data obtained is the data with 0 as the average and 1 as the standard deviation. The purpose of data centralization is to unify the scale of data of different variables.
raw data

# -*- coding: utf-8 -*-
"""
Created on Tue Oct  5 10:06:41 2021

@author: Machi
"""
import pandas as pd
import statsmodels.formula.api as smf
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from statsmodels.stats.api import anova_lm

# Read the data in CSV
df = pd.read_csv('data.csv')
print(df)

# We use Pearson coefficient to calculate the correlation between columns
c_matrix = df.corr(method='pearson')
print(c_matrix)

# Draw a three-dimensional scatter diagram
fig=plt.figure()
ax1 = Axes3D(fig)
ax1.scatter3D(df['x1'],df['x2'],df['y'], cmap='Blues')
plt.show()

# Substitute the data for fitting
result = smf.ols('y~x1+x2-1',data = df).fit()
print(result.summary())

y_fitted = result.fittedvalues

# Analysis of variance was performed for each coefficient
table = anova_lm(result, typ=3)
print(table)

# Centralization and standardization
dfcenter = df-df.mean()
dfnorm = (df-df.mean())/df.std()

print(dfnorm)

output



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/293883.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号