Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- from scipy import optimize
- df = pd.read_csv('SolverPython.csv')
- ## Here I am trying to reduce the total error rate with the equation, error = sum ((actual_value - predicted_value)/actual_value), where predicted value is given by the equation of linear regression(y = intercept + betas*x)
- def equation(x, df):
- totalError = sum(abs(df['target'] - (66.75 - 0.9*df['variable1']* x[0]
- - 14.02*df['v2'] * x[1]
- - 2.57* df['v3'] * x[2]
- + 0.82 * df['v4'] * x[3]))/ df['target'])
- return totalError
- x0 = [1, 1, 1, 1] ### initialize the values of unknowns, which u want to optimize.
- res = optimize.minimize(fun=equation, x0=np.array(x0), args=(df), method='SLSQP', bounds=[(0,20),(0,20),(0,20),(0,20)])
- print(res)
- print(res.x) ## to print the optimized values of x
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement