Scipy优化机器学习模型
最近,我一直面临一个问题,我认为Scipy可能是一个很好的解决方案。但是,我无法正确应用它。不确定我是否缺少某些东西,或者我正在寻找的东西实际上根本不可能。
这是一个虚构的示例,我为使事情变得更加清晰,更易于可视化。我的情况更加复杂。但是,我想发现的是,会有多少狗和猫给出特定数量的老鼠?
from sklearn.svm import SVR
from scipy.optimize import minimize
from sklearn.ensemble import RandomForestRegressor
import numpy as np
import pandas as pd
n_dogs = [10, 5, 5, 2, 19, 12, 1,2]
n_cats = [5, 100, 5, 3, 1000, 0, 1,2]
n_rats = [100, 0, 50, 30, 0, 1000, 10, 5]
X = np.array([n_dogs, n_cats]).T
y = np.array([n_rats]).T
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
model = RandomForestRegressor()
model.fit(X,y)
#Boundaries of condition
bnds = [(100,500), (100,150)]
#Initial guesses
x0 = [300,125]
#Predict from condition
residual_plant = minimize(lambda x: model.predict([[12,8]]), x0, method='SLSQP',bounds=bnds,options = {'eps': np.radians(5.0)})
print(residual_plant)```
Recently I have been facing a problem which I think that SciPy might be a good candidate to solve. However, I have not been able to properly apply it. Not sure if I am missing something or if what I am looking for is actually not possible at all.
This is a fictitious example which I made to makes things more clear and easier to visualize. My case is way more complicated. However, what I want to find out is how many dogs and cats would there be given a specific number of rats?
from sklearn.svm import SVR
from scipy.optimize import minimize
from sklearn.ensemble import RandomForestRegressor
import numpy as np
import pandas as pd
n_dogs = [10, 5, 5, 2, 19, 12, 1,2]
n_cats = [5, 100, 5, 3, 1000, 0, 1,2]
n_rats = [100, 0, 50, 30, 0, 1000, 10, 5]
X = np.array([n_dogs, n_cats]).T
y = np.array([n_rats]).T
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
model = RandomForestRegressor()
model.fit(X,y)
#Boundaries of condition
bnds = [(100,500), (100,150)]
#Initial guesses
x0 = [300,125]
#Predict from condition
residual_plant = minimize(lambda x: model.predict([[12,8]]), x0, method='SLSQP',bounds=bnds,options = {'eps': np.radians(5.0)})
print(residual_plant)```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论