Untitled

mail@pastecode.io avatar
unknown
python
2 months ago
816 B
2
Indexable
Never
from sklearn import datasets, linear_model
from sklearn.preprocessing import MinMaxScaler
from my_sql_db import *

class LinearRegressionEstimator():

def fit(X,y):
	self.estimator = linear_model.LinearRegression()
	self.estimator.fit(X,y)

	def predict(X):
		return self.estimator.predict(X)

class LinearRegressionEstimatorWithMinMaxMySQLDatabase(LinearRegressionEstimator):
	def fit(X_columns,y_columns):
		db = SQLConnector(user ='me', password = '1234', db ='ds')
		query = 'select * from my_table'
		  
		df = db.query(query)
		X,y = df[X_columns],y = df[y_columns]

		self.estimator = linear_model.LinearRegression()
		self.preprocessor = MinMaxScaler()
		X = MinMaxScaler().fit_transform(X)
		self.estimator.fit(X,y)

	def predict(X):
		X = self.preprocessor.transform(X)
		return self.estimator.predict(X)

Leave a Comment