简体   繁体   English

量化神经网络python的预测质量

[英]Quantifying the quality of predictions of the neural network python


Today i'd like to ask you some help with the quality of my neural network. 今天,我想请教您一些有关神经网络质量的帮助。 I've been working with a project to predict parameters in metallurgy. 我一直在与预测冶金学参数的项目合作。 To make sure that my neural network is going on the right way i tried to use some functions of "Scikit-learn" like "score" and "r^2" but no success. 为了确保我的神经网络运行正确,我尝试使用“ Scikit-learn”的某些功能,例如“ score”和“ r ^ 2”,但没有成功。

With the actual code my "r²" is -10.42239374572942, this value is unreal because everybody knows the r² must be between -1 and 1. 在实际代码中,我的“r²”是-10.42239374572942,此值是不真实的,因为每个人都知道r²必须在-1和1之间。

Anyone have any suggestion to evaluate my neural network? 有人对我的神经网络有任何建议吗? Why my code is not working? 为什么我的代码无法正常工作?

Thaks guys. 解冻的家伙。 See you. 再见。

Follow above my code: 按照我的代码上面:

# coding: utf-8

import pandas as pd
import numpy as np

#modulo de plot
import matplotlib.pyplot as plt

#modulo da rede propriamente dita
from sklearn.neural_network import MLPRegressor

#para testar a rede neural
from sklearn.model_selection import train_test_split

#para normalização
from sklearn.preprocessing import StandardScaler

#para testar a qualidade da rede neural
from sklearn.metrics import mean_squared_error, r2_score

#buscando o CSV com os dados do AF1-Gerdau
df = pd.read_csv('Rede3.03.11.17_MOACIR_b.csv', delimiter=';', encoding = "ISO-8859-1" )

df2 = df.dropna(how='all')


# ## Definindo as variáveis inputs e a resposta

X = df2.drop(['Fuel Rate'], axis=1) #deixando todas as colunas exceto a variável resposta "Fuel Rate"
y = df2['Fuel Rate'] #variável respota "Fuel Rare"

# ## Normalizando os dados para uma melhor convergência

scaler = StandardScaler()
X_train, X_test, y_train, y_test = train_test_split(X, y)

# Treinamento apenas com os dados de treino
scaler.fit(X_train)

# Aplicando a transformação de normalização dos dados:
X_train = scaler.transform(X_train)
X_test = scaler.transform(X_test)

# ## Criando os parametros da RNA
rna = MLPRegressor(hidden_layer_sizes=(13,13,13), max_iter=2000)

# ## Treinando a RNA
rna.fit(X_train,y_train)

# ## Testando a rede
y_predicted = rna.predict(X_test)

# The coefficients
print('Coefficients: \n', r2_score(y_test, y_predicted))

To start with, the r2_score() metric can be arbitrarily low. 首先, r2_score()指标可以任意低。 It need not be between -1 and 1 and does not correspond to the pearson correlation coefficient. 它不必介于-1和1之间,也不必对应于皮尔逊相关系数。 A score of ~-10 then just means that the model is performing significantly worse than a model which outputs mean values (corresponding to an r2 score of 0). 〜-10的分数仅表示该模型的性能明显差于输出平均值的模型(对应于r2分数为0)。

The r2_score() you chose is a fine preliminary metric for your model. 您选择的r2_score()是适合您的模型的初步指标。 The output looks strange not because there is a problem with the metric but because there is a problem with the model. 输出看起来很奇怪,不是因为度量标准存在问题,而是因为模型存在问题。 In its current state, improving r2_score() will probably improve any other metric of interest. 在当前状态下,改进r2_score()可能会改善其他任何感兴趣的指标。 You might also be interested in the similarity between metrics on your test set and metrics on your train set -- the more similar they are the more likely your model is to generalize well (under the manifold hypothesis or any other framework avoiding no free lunch theorems). 您可能还对测试集上的度量标准与训练集上的度量标准之间相似性感兴趣-它们越相似,您的模型就越有可能被很好地概括(在多重假设或任何其他框架下,避免没有免费的午餐定理) )。 Depending on the intended application, you might care about the worst case scenario -- it might not matter if you have an r2 of 0.999 if the worst case is that a self driving car mistakes a pedestrian for a safe place to drive. 根据预期的应用程序,您可能会担心最坏的情况 -如果r2为0.999(如果最坏的情况是自动驾驶汽车将行人误认为是安全的驾驶场所),则可能无关紧要。 You might be interested in a wide range of calibration scores -- if your model predicts a strong pattern with good accuracy but the residuals demonstrate a strong bias in the model, something may very well be amiss. 您可能会对广泛的校准分数感兴趣-如果您的模型预测出具有良好准确性的强模式,但残差在模型中显示出强烈的偏差,则很可能不对。 In general, the quality of a model depends strongly on its intended application, and your metrics should reflect your end goals. 通常,模型的质量在很大程度上取决于其预期的应用程序,并且您的指标应反映最终目标。 Using The Case for Learned Index Structures as an example, sometimes generalization is a bad thing and not what you want at all. 以学习索引结构案例为例,有时泛化是一件坏事,根本不是您想要的。

Several potential problems exist in your approach. 您的方法中存在几个潜在的问题。 I'm not quite sure about metallurgy, but many chemistry problems have chaotic interaction dynamics and are not easily modeled with a naive approach which just slaps a model onto the input data (naive is not meant negatively here -- the naive approach is often a good starting point and may completely satisfy the requirements at hand). 我对冶金学不太确定,但是许多化学问题都具有混乱的相互作用动力学,并且不容易用朴素的方法建模,因为朴素的方法只是将模型放在输入数据上(朴素在这里并不意味着否定-朴素的方法通常是良好的起点,并且可以完全满足当前的要求)。

As a rule of thumb, most of the gains you will find are going to be in feature engineering. 根据经验, 您将发现大部分收益都来自功能工程。 In the case of chemical problems, this can involve taking the outputs from standard solutions to the problem (which are obviously insufficient since you're going straight for machine learning) and treating them as features in your neural network. 在化学问题的情况下,这可能涉及从标准解决方案获取问题的输出(由于您直接进行机器学习,这显然是不够的),并将其视为神经网络的特征。 The idea is that even though no individual model is perfect, they're all right often enough and wrong in different ways so that the neural network is able to figure out how to combine them together to create a better answer. 这样的想法是,即使没有一个单独的模型是完美的,但它们以不同的方式常常是对是错,以便神经网络能够弄清楚如何将它们组合在一起以创建更好的答案。 This is a type of ensemble technique. 这是一种合奏技术。

What data visualizations/analysis have you done? 您完成了哪些数据可视化/分析? Do you have an idea of which features correspond to the output you're trying to predict? 您是否知道哪些功能与您要预测的输出相对应? It's even possible that the input you have does not have enough information to predict your desired output. 您输入的内容甚至可能没有足够的信息来预测所需的输出。 Have you examined the data before dropping the NaN values? 在删除NaN值之前,您是否检查过数据? Would a better imputation method yield additional gains? 更好的插补方法会带来额外收益吗? Your model is coded fine. 您的模型编码良好。 Understanding your data is easily the most important task at hand. 了解您的数据很容易是手头最重要的任务。

Scikit-learn can have problems optimizing networks with small numbers of nodes in each layer. Scikit-learn在优化每层节点数量少的网络时可能会遇到问题。 A grid search and cross validation procedure to help determine the optimal parameters may improve your model substantially. 可以帮助确定最佳参数的网格搜索和交叉验证过程可能会大大改善您的模型。 The solution might be sensitive to tolerances and other such parameters. 该解决方案可能对公差和其他此类参数敏感。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM