简体   繁体   English

使用scikit-Learn建立乘法分类模型

[英]Using scikit-Learn for a multiplicative, categorical model

I have a dataset (rental price vs. number of bedrooms and neighborhood). 我有一个数据集(租金价格与卧室和附近的数量)。

I want to model the rental price as a multiplication of a base price, a scalar related to number of bedrooms and a scalar related to neighborhood. 我想将租金价格建模为基本价格,与卧室数量相关的标量和与邻域相关的标量的乘积。

eg for a 2-bed in Mayfair it may be R = $100*1.2*1.5 例如,在梅费尔(Mayfair)的两张床可能是R = $ 100 * 1.2 * 1.5

Mathematically I guess this would look like: rental price = base*(a1B1+a2B2+a3B3...)*(k1N1+k2N2+...) 从数学上讲,我想这看起来像:租金=基础*(a1B1 + a2B2 + a3B3 ...)*(k1N1 + k2N2 + ...)

Where B2 is a binary variable, 1 if the property has 2-bedrooms and otherwise 0; 其中B2是二进制变量,如果属性具有2个卧室,则为1,否则为0; a2 would be 1.2 in the above example; 在上面的示例中,a2为1.2; N1 is a binary variable, 1 if the property is in 'Neighborhood 1', etc. N1是一个二进制变量,如果属性位于“ Neighborhood 1”中,则为1,依此类推。

Can scikit-learn help model such a thing? scikit-learn能帮助建模这样的事情吗? I can model a linear combination of my variables: 我可以对变量进行线性组合建模:

price = a1B1 + a2B2 + ... + k1N1 + k2N2 价格= a1B1 + a2B2 + ... + k1N1 + k2N2

But I cannot see any way to model a multiplicative model, nor any way to turn a multiplicative model with categorical variables into a linear model. 但是我看不到任何对乘法模型进行建模的方法,也看不到将具有分类变量的乘法模型转换为线性模型的任何方法。

This is a simple linear regression problem. 这是一个简单的线性回归问题。 House prices regression is the most famous use case of linear regression. 房价回归是线性回归最著名的用例。 You can import it : 您可以导入它:

from sklearn.linear_model import LinearRegression
linear_model = LinearRegression()
linear_model.fit(X_training, y_training)
# Where X = features that you can provide in a dataframe or numpy matrix
# y = House prices
prices = linear_model.predict(X_test)
# ^Gives the prediction for the prices

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

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