[英]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.