简体   繁体   English

如何修复“警告(来自警告模块):”使用Sklearn和Python

[英]How to fix “Warning (from warnings module):” using Sklearn and Python

I wrote a code for logarithmic regression using Python and Sklearn. 我使用Python和Sklearn编写了一个用于对数回归的代码。 I have downloaded dataset from the web *( http://archive.ics.uci.edu/ml/machine-learning-databases/concrete/compressive/ ). 我从网上下载了数据集*( http://archive.ics.uci.edu/ml/machine-learning-databases/concrete/compressive/ )。 My program works good, but it gives me working that looks like this: 我的程序运行良好,但它让我的工作看起来像这样:

Warning (from warnings module):
  File "C:\Users\Pc\AppData\Local\Programs\Python\Python36-32\lib\site-packages\sklearn\preprocessing\_function_transformer.py", line 98
    "validate=False in 0.22.", FutureWarning)
FutureWarning: The default validate=True will be replaced by validate=False in 0.22.

I googled it and I havent find anything. 我用Google搜索,我找不到任何东西。 I see that it shows me line 98 but I do not have 98 lines in my code. 我看到它显示了line 98 98行,但我的代码中没有98行。 Does anyone knows whats the problem? 有谁知道这个问题是什么?

This is the code: 这是代码:

import numpy as np
import pandas as pd
import math
from sklearn import linear_model
from sklearn.preprocessing import PolynomialFeatures
from sklearn.preprocessing import FunctionTransformer

#Reading data from excel and rounding values on 2 decimal places
data = pd.read_excel("DataSet.xls").round(2)
data_size = data.shape[0]

#some values are 0, so I need to eliminate them because I cant do log 0 function
my_data = data[(data["Superpl"] == 0) &
               (data["FlyAsh"] == 0) &
               (data["BlastFurSlag"] == 0)].drop(columns=["Superpl","FlyAsh","BlastFurSlag"])


def logarithmic_regression(input_data, cement, water, coarse_aggr, fine_aggr, days):

    variables = input_data.iloc[:,:-1]
    results = input_data.iloc[:,-1]

    n = results.shape[0]
    results = results.values.reshape(n,1) #reshaping the values so that variables and results have the same shape

    #transforming x data to logarithmic fucntion
    log_regression = FunctionTransformer(np.log)
    log_variables = log_regression.fit_transform(variables)

    #making linear model and fitting the logarithmic data into linear model
    regression = linear_model.LinearRegression() 
    model = regression.fit(log_variables, results)

    input_values = [cement, water, coarse_aggr, fine_aggr, days]

    #transforming input data for prediction in logarithmic function
    input_values = log_regression.transform([input_values]) 

    #predicting the outcome based on the input_values
    predicted_strength = regression.predict(input_values) #adding values for prediction
    predicted_strength = round(predicted_strength[0,0], 2)

    return "Logarithmic prediction: " + str(predicted_strength)


print(logarithmic_regression(my_data, 339.0, 197.0, 968.0, 781.0, 14))

I fixed it: 我修好了它:

log_regression = FunctionTransformer(np.log, validate=True)

This will fix the warning. 这将修复警告。

暂无
暂无

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

相关问题 忽略来自Python模块(seaborn,sklearn)的警告 - Ignore warnings in from Python modules (seaborn, sklearn) 如何修复“ImportError: cannot import name '_raise_dep_warning_if_not_pytest' from 'sklearn.utils.deprecation'”? - How to fix “ImportError: cannot import name '_raise_dep_warning_if_not_pytest' from 'sklearn.utils.deprecation'”? Python Sklearn - 弃用警告 - Python Sklearn - Deprecation Warning Python:无法修复“ModuleNotFoundError:没有名为‘sklearn’的模块” - Python: Can't fix "ModuleNotFoundError: No module named 'sklearn' " Python sklearn GaussianNB:“ MemoryError”,但没有解决方法的线索 - Python sklearn GaussianNB : “MemoryError” but no leads on how to fix 如何在Python sklearn中修复SVR图 - How to fix SVR plot in Python sklearn "<i>Warning (from warnings module): ResourceWarning: unclosed<\/i>警告(来自警告模块):ResourceWarning:未关闭<\/b><socket.socket object, fd=404, family=2, type=1, proto=0><i>using selenium<\/i>使用硒<\/b>" - Warning (from warnings module): ResourceWarning: unclosed <socket.socket object, fd=404, family=2, type=1, proto=0> using selenium ModuleNotFoundError:没有名为“sklearn.cross_validation”的模块?? 如何解决? - ModuleNotFoundError: No module named 'sklearn.cross_validation' ?? How to fix it? 使用 unpack 方法来自 tika python 模块的警告消息 - Warning message from tika python module using the unpack method 如何解决问题“ModuleNotFoundError: No module named &#39;sklearn&#39; - How do I fix the issue "ModuleNotFoundError: No module named 'sklearn'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM