擅长:python、mysql、java
<p>您错过了基本步骤“规范化数据”</strong></p>
<h3>修复</h3>
<pre><code>df = pd.DataFrame({'p': [15-x for x in range(14)]
, 'x': [x for x in range(14)]})
df['y'] = 1000 * (10 / df['p'])
# Normalize the data (x - mean(x))/std(x)
s_p = np.std(df['p'])
m_p = np.mean(df['p'])
s_y = np.std(df['y'])
m_y = np.mean(df['y'])
df['p_'] = (df['p'] - s_p)/m_p
df['y_'] = (df['y'] - s_y)/m_y
# Fit and make prediction
nlm = SVR(kernel='rbf').fit(df[['p_']], df['y_'])
df['nml'] = nlm.predict(df[['p_']])
# Plot
plt.plot(df['p_'], df['y_'], 'r')
plt.plot(df['p_'], df['nml'], 'g')
plt.show()
# Rescale back and plot
plt.plot(df['p_']*s_p+m_p, df['y_']*s_y+m_y, 'r')
plt.plot(df['p_']*s_p+m_p, df['nml']*s_y+m_y, 'g')
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/sdc6Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sdc6Z.png" alt="enter image description here"/></a></p>
<p><a href="https://i.stack.imgur.com/syUsc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/syUsc.png" alt="enter image description here"/></a></p>