简体   繁体   中英

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

Mathematically I guess this would look like: rental price = base*(a1B1+a2B2+a3B3...)*(k1N1+k2N2+...)

Where B2 is a binary variable, 1 if the property has 2-bedrooms and otherwise 0; a2 would be 1.2 in the above example; N1 is a binary variable, 1 if the property is in 'Neighborhood 1', etc.

Can scikit-learn help model such a thing? I can model a linear combination of my variables:

price = 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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