2.7房价预测val_accuracy一直是.0016
来源:2-7 实战回归模型
pythoner_
2020-09-09
老师你好,2.7房价预测,我跟您的代码一致,但是val_accuracy一直是.0016,最终验证也是很低
我在尝试改了学习率以及0.1,0.001.0.01但是正确率依旧上不去
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import sklearn
import pandas as pd
import os
import sys
import time
import tensorflow as tf
from tensorflow import keras
print(tf.__version__)
print(sys.version_info)
for modul in mpl, np, pd, tf, sklearn:
print(modul.__name__, modul.__version__)
from sklearn.datasets import fetch_california_housing
housing = fetch_california_housing()
print(housing.DESCR)
print(housing.data.shape)
print(housing.target.shape)
import pprint
pprint.pprint(housing.data[0:5])
from sklearn.model_selection import train_test_split
x_train_all, x_test, y_train_all, y_test = train_test_split(
housing.data, housing.target, random_state=7)
x_train, x_valid, y_train, y_valid = train_test_split(
x_train_all, y_train_all)
print(x_train.shape, y_train.shape)
print(x_valid.shape, y_valid.shape)
print(x_test.shape, y_test.shape)
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
x_train_scaled = scaler.fit_transform(x_train)
x_test_scaled = scaler.transform(x_test)
x_valid_scaled = scaler.transform(x_valid)
model = keras.models.Sequential([
keras.layers.Dense(30, activation='relu', input_shape=x_train.shape[1:]),
keras.layers.Dense(1)])
model.summary()
model.compile(loss='mean_squared_error', optimizer=keras.optimizers.SGD(0.1), metrics=['accuracy'])
callbacks = [keras.callbacks.EarlyStopping(patience=5, min_delta=1e-6)]
model.fit(x_train_scaled, y_train,
validation_data=(x_valid_scaled, y_valid),
epochs=100,)
model.evaluate(x_test_scaled, y_test)
如果老师有空,希望解答一下,感谢~
写回答
1回答
-
正十七
2020-09-17
同学你好,房价预测是一个回归问题,即预测出正确的实数,所以只有loss,没有accuracy,不能用accuracy来衡量, loss衡量的是预测出来的值和实际值的差距,如果你的loss值是0.016的话,那么说明模型拟合的很好。
20
相似问题