python import numpy as np import pandas as pd import matplotlib.pyplot as plt from scipy import stats from sklearn.linear_model import LinearRegression x = np.array([1, 2, 3, 4, 5]) y = np.array([3, 4, 5, 6, 7]) x_mean = np.mean(x) y_mean = np.mean(y) x_std = np.std(x) y_std = np.std(y) x_normalized = (x - x_mean) / x_std y_normalized = (y - y_mean) / y_std pearson_corr, _ = stats.pearsonr(x, y) df = pd.DataFrame({'x': x, 'y': y}) df_summary = df.describe() model = LinearRegression() model.fit(x.reshape(-1, 1), y) y_predicted = model.predict(x.reshape(-1, 1)) plt.scatter(x, y, color='b', label='Data') plt.plot(x, y_predicted, color='r', label='Linear Regression') plt.xlabel('x') plt.ylabel('y') plt.title('Data Analysis') plt.legend() plt.show() pip install numpy pandas matplotlib scipy scikit-learn


上一篇:
下一篇:
切换中文