sklearn实现线性回归与改变损失函数

2021-01-14 11:46:09 浏览数 (1)

文章目录

  • sklearn learn

sklearn learn

代码语言:javascript复制
# -*- coding:utf-8 -*-
# /usr/bin/python

import matplotlib.pyplot as plt
import numpy as np

a = [[1,2,3,4],[2,3,4,5],[3,4,5,6],]
b = [2,2,2,2]
c = np.multiply(a,b)
print(c,type(c))

b1 = [[2],[2],[3],[4]]

c = np.dot(a,b1)
print(c,type(c))

from sklearn.datasets import load_boston
from sklearn.linear_model import LinearRegression,SGDRegressor, Ridge, LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import mean_squared_error, classification_report
from sklearn.externals import joblib
import pandas as pd
import numpy as np


def mylinear():
    """
    线性回归直接预测房子价格
    :return: None
    """
    # 获取数据
    lb = load_boston()

    # 分割数据集到训练集和测试集
    x_train, x_test, y

0 人点赞