- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 Python 和 sklearn 编写了多项式回归的代码。我使用预处理和 PolynomialFeatures 来转换数据。是否可以使用预处理并转换我的数据,以便我可以进行对数回归?我到处都找过了,但什么也没找到。这是多项式回归的代码,我的问题是,如何将此代码更改为对数回归:
import numpy as np
import pandas as pd
import math
import xlrd
from sklearn import linear_model
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import PolynomialFeatures
#Reading data from excel
data = pd.read_excel("DataSet.xls").round(2)
data_size = data.shape[0]
#print("Number of data:",data_size,"\n",data.head())
def polynomial_prediction_of_future_strength(input_data, cement, blast_fur_slug,fly_ash,
water, superpl, coarse_aggr, fine_aggr, days):
variables = prediction_accuracy(input_data)[2]
results = prediction_accuracy(input_data)[3]
n = results.shape[0]
results = results.values.reshape(n,1) #reshaping the values so that variables and results have the same shape
#transforming the data into polynomial function
Poly_Regression = PolynomialFeatures(degree=2)
poly_variables = Poly_Regression.fit_transform(variables)
#accuracy of prediction(splitting the dataset on train and test)
poly_var_train, poly_var_test, res_train, res_test = train_test_split(poly_variables, results, test_size = 0.3, random_state = 4)
input_values = [cement, blast_fur_slug, fly_ash, water, superpl, coarse_aggr, fine_aggr, days]
input_values = Poly_Regression.transform([input_values]) #transforming the data for prediction in polynomial function
regression = linear_model.LinearRegression() #making the linear model
model = regression.fit(poly_var_train, res_train) #fitting polynomial data to the model
predicted_strength = regression.predict(input_values) #strength prediction
predicted_strength = round(predicted_strength[0,0], 2)
score = model.score(poly_var_test, res_test) #accuracy prediction
score = round(score*100, 2)
accuracy_info = "Accuracy of concrete class prediction: " + str(score) + " %\n"
prediction_info = "Prediction of future concrete class after "+ str(days)+" days: "+ str(predicted_strength)
info = "\n" + accuracy_info + prediction_info
return info
#print(polynomial_prediction_of_future_strength(data, 214.9 , 53.8, 121.9, 155.6, 9.6, 1014.3, 780.6, 7))
最佳答案
如果您想实现平稳过渡,最好的方法是使用 scikit-learn 的风格定义您自己的估计器。您可以找到更多信息here .
这是一种可能性:
from sklearn.base import BaseEstimator, TransformerMixin
class LogarithmicFeatures(BaseEstimator, TransformerMixin):
def __init__(self):
pass
def fit(self, X, y=None):
self.n_features_ = X.shape[1]
return self
def transform(self, X, y=None):
if X.shape[1] != self.n_features_:
raise ValueError("X must have {:d} columns".format(self.n_features_))
return np.log(X)
然后您可以使用以下方法将其插入代码中:
lf = LogarithmicFeatures()
log_variables = lf.fit_transform(variables)
关于python - 在 Python 中使用 sklearn.preprocessing 进行数据转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55112074/
我理解缩放意味着以均值 (mean=0) 为中心并使单位方差 (variance=1)。 但是,scikit-learn 中的 preprocessing.scale(x) 和 preprocessi
我有一个以 float 作为数据的数据框,我想规范化数据,所以首先我将其转换为 int (否则我会出现错误 ValueError: 输入包含 NaN、无穷大或对于 dtype 来说太大的值('floa
我计划分发 SubSpec (适合 < 600 行的 xUnit 的小型 BDD 扩展)作为单个 .cs 文件而不是完整的 dll。 SubSpec 具有 Silverlight 和 .NET 风格,
我一直在探索用于变量转换的新 recipes 包,作为机器学习管道的一部分。由于所有新扩展,我选择了这种方法 - 从使用 caret 的 preProcess 函数升级。但我发现这些包对于转换后的数据
我有一个名为 size_array 的连续变量列表。我一直在像这样从 [0, 1] 缩放它们: max_abs_scaler = preprocessing.MinMaxScaler() scaled
我正在使用可视化 cl.exe 编译器在预处理后获取中间文件。所有的 #define 都被删除了。有没有可能将它们保留在中间文件中? 最佳答案 没有。预处理的任务之一是删除所有 #define 和其他
我想处理我的数据中的 NA 值,但不想缩放和居中,所以我只是这样做: preProcess(data, method = "knnImpute", k=10) 或这个: preProcess(data
如何获取tf.keras.preprocessing.image_dataset_from_directory中的文件个数? train_ds = tf.keras.preprocessing.ima
在 sklearn documentation说“规范”可以是其中之一 norm : ‘l1’, ‘l2’, or ‘max’, optional (‘l2’ by default) The norm
我想在触摸 UIButton 时添加动画效果。有没有办法在 Button 被发送到它的操作之前运行一个函数? 最佳答案 当您开始按下按钮时将调用以下操作。 @IBAction internal fun
我已经阅读了 scikit learn 网站上的手册,但我仍然不知道该命令背后的数学公式是什么。 >>> from sklearn import preprocessing >>> import nu
我想知道是否可以使用 gcc 输出“预处理”代码但“忽略”(不扩展)包括: ES 我得到了这个主要的: #include #define prn(s) printf("this is a macro
Python 3.5,来自 sklearn 的预处理 df = quandl.get('WIKI/GOOGL') X = np.array(df) X = preprocessing.scale(X)
为了正确调试 C++ 中的复杂宏,我通常在它们上运行预处理器,以便准确查看生成的代码的样子。 有类似“预处理”模板代码的方法吗? 最佳答案 一种方法(依赖于编译器)是在每个编译器步骤之后使用转储。我写
我正在尝试从 Sklearn 导入 StandardScalar,进行预处理,但它一直给我一个错误。 这是确切的错误: ImportError
如果客户端有办法 GWT 在客户端计算机上预处理文件的代码? 例如,在将文件提交到服务器之前计算它的校验和。 最佳答案 不,这是不可能的。文件的操作是由浏览器完成的,而不是 HTML 代码。 想想看,
我正在关注 this文档聚类教程。作为输入,我提供了一个可以下载的 txt 文件 here .它是 3 个其他 txt 文件的组合文件,使用\n 分隔。创建 tf-idf 矩阵后,我收到此警告: ,,
$ cabal install arithmoi-0.4.0.3 导致多个错误,例如: Math/NumberTheory/Moduli.hs:489:4: error: invalid p
#define A(a) "str" ## a ## test A(_) 根据 17.6.4.3.5在 C++11 标准中 Literal suffix identifiers that do no
我正在使用sklearn.neural_network.MLPClassifier构建神经网络: clf = sklearn.neural_network.MLPClassifier(hidd
我是一名优秀的程序员,十分优秀!