- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一些图表。所有这些图表都是两个参数(Alpha 和 Beta)的函数。然而这个功能尚不清楚。我唯一知道的是,通过更改 Alpha 和 Beta,函数的形状会发生变化,但不清楚这两个参数如何影响该函数的形状。
我想使用机器学习工具(最好是 scikit-learn)通过提供任意图表来预测组件 Alpha 和 Beta。我将提供更多细节:假设我有 3 个基于存储在 3 个文本文件中的点的图表:
#First graph: 1.txt
89.3131996411674 0.0
86.31206459803472 1.9218574062324632
81.87220673358236 4.212444252488191
76.41926314984194 7.090515235715248
69.70749592038558 10.46295619504502
4.695619238294171 42.982945242832166
#Second graph: 2.txt
89.31085880364263 0.0
86.14246621045181 0.11975843148903698
81.48739328101496 0.7686454222842645
75.88152851199536 1.501591710302762
69.15242620019211 4.034900351905526
4.674145681785713 41.09359256010945
#Third graph: 3.txt
89.30979468139782 0.0
86.05550911873416 -0.9850540767366983
81.20598538751082 -1.1003291465972356
75.39779664162057 -2.714132118366186
68.62777149709575 -1.3767373919651047
4.653517556961358 39.28302423686896
现在,如果我使用以下代码绘制它们:
import matplotlib.pyplot as plt
plt.plotfile('1.txt', delimiter=' ', cols=(0, 1),linestyle='--',linewidth=3,color='k',label=r'$1:Alpha\/\/=20\/\/and\/\/Beta\/\/=5$')
plt.plotfile('2.txt', delimiter=' ', cols=(0, 1),linestyle='-',linewidth=3,color='m',label=r'$2:Alpha\/\/=30\/\/and\/\/Beta\/\/=0.3$',newfig=False)
plt.plotfile('3.txt', delimiter=' ', cols=(0, 1),linestyle='-.', linewidth=3,color='r',label=r'$3:Alpha\/\/=40\/\/and\/\/Beta\/\/=0.2$',newfig=False)
lg=plt.legend(ncol=1, loc=2, fontsize=13)
plt.xlabel(r'$\mathrm{X}$', fontsize=16)
plt.ylabel(r'$\mathrm{Y}$', fontsize=16)
axes = plt.gca()
plt.gca().invert_xaxis()
plt.tick_params(axis='both', which='major', labelsize=13)
plt.show()
结果将是:
现在我想给出一个任意图(点),我希望机器学习算法能够预测系数 Alpha 和 Beta。我需要指出的是,为了简单起见,我在这里只提供了 3 个图表,而实际上我有 1000 多个图表,并且所有图表都位于 graph.1 和 graph.3 之间。例如,如果我向代码提供与 graph.3 完全相同的点并要求预测 Alpha 和 Beta ,我期望得到:
Alpha = 40
Beta = 0.2
或者,如果我向代码给出与 graph.1 完全相同的点并要求预测 Alpha 和 Beta ,我期望得到:
Alpha = 20
Beta = 5
我不知道机器学习是否能够为我做到这一点,因为我不知道 Alpha 和 Beta 到底如何影响图表的形状。 我只知道图表依赖于这两个组件,但我不知道这个函数是什么
我希望如果我为算法提供合理数量的图表(作为输入)作为训练集,代码可以预测(估计)任意给定点(图表)的 Alpha 和 Beta。
预先感谢您的时间和帮助!
最佳答案
从你的问题解释来看,不清楚你是否有每个 1000 图表的 alpha 和 beta 值,我假设你没有,你只有值。如果是这种情况,我假设上面的 alpha = 0.4
和 beta = 0.2
只是一些虚拟值。
如果您假设您的图形是直线,您可以使用线性回归来创建给定图形的参数 a 和 b 的估计值,它们对应于拦截器(下面方程中的 a)和系数(下面方程中的 b)。通过这样做,您将了解 a 和 b 如何影响给定图形的函数形状。换句话说,您将了解什么是函数。
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
df = pd.read_csv("1.txt", delimiter="\t")
x = df.x.values.reshape(-1, 1)
y = df.y.values.reshape(-1, 1)
model = LinearRegression(fit_intercept=True)
model.fit(x, y)
# This corresponds to a and b from equation above
print(model.coef_, model.intercept_)
但是,如果您的图形不是直线,您可以使用多项式回归。假设您认为您的函数是 2 次多项式,那么您将得到以下方程:
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
df = pd.read_csv("1.txt", delimiter="\t")
x = df.x.values.reshape(-1, 1)
y = df.y.values.reshape(-1, 1)
poly = PolynomialFeatures(degree=2)
X_ = poly.fit_transform(x) # Transforming into degree two polynomial
model = LinearRegression(fit_intercept=True)
model.fit(X_, y)
# This corresponds to a,b and c from equation above
print(model.coef_, model.intercept_)
如果您愿意,您可以使用更高阶的多项式,它们将适合更复杂的函数。
通过完成所有这些,您将学习参数以了解给定的 x,输出是什么y。这不是你所描述的问题。您想了解alpha和beta是什么。
如果您仔细阅读我所写的内容,您可能会发现 alpha 和 beta 是一些参数(例如 a、b、c 等),但为了计算出它们的近似值,您必须知道使用了多项式函数的次数,然后找出所使用的参数(a、b、c 等)alpha 和 beta 是哪一个。
关于python - 如何在 scikit-learn 中预测未知函数的组成部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54163935/
我有一个交叉表函数,我过去曾多次成功使用它,但现在它在最后转储所有数据,而不是将其旋转到输出表中。它似乎无法找到交叉表。我通过以下方式对其进行了研究; 如果 tablefunc 不存在则创建扩展; -
表1(客户表) Id, CustomerId, IsKnownCustomer,phonemacaddress 1, 空 0 00:9a:34:cf:a4 2, 004024 1 00:6f:64:c
知道为什么我总是收到这个烦人且无用的错误代码/描述吗? Failed to pull image myapidemodocker.azurecr.io/apidemo:v4.0: rpc error:
我正在进行 PHP 登录,并且之前可以正常工作,但我尝试使用户名功能不区分大小写,但此后代码一直无法正常工作。我删除了我添加的所有内容,以尝试使其不区分大小写,即 strtolower()。页面上显示
有人会帮助我提供有关此错误的任何可能信息吗?原因?登录?在哪里寻找/开始? Cannot use output buffering in output buffering display handl
我已经添加了这样的脚本 我在我的 test.js 中做了这个 var app = angular.module('MyApp', ['ngRoute']).config
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 8 年前。 Improve this qu
我有这个sql语句: selectAllUsersByCriteria = 连接.prepareStatement( “从用户那里选择*?=?” ); 下面的方法运行该语句: public Array
我有一个白色的 EditText,在 Android 3.1 及更高版本中,光标不显示(因为它也是白色的)。有关信息,我使用 android:background="@android:drawable
我正在尝试使用 Keras 实现深度学习模型。但是我有一个未知形状实现的问题。我一直在寻找类似的错误,但没有找到。 这是我的代码。 Xhome = dataset[:,32:62] Xaway = d
关注此introduction可以通过导入命名空间 System.Xml 来使用 XMLReader 类。在我的 Visual Studio 项目中,我使用 .NET 4.0,但 System.Xml
我有一个动态链接库的程序。该程序将函数指针传递给该库以执行。 但是 ubsan(Undefined Behavior Sanitizer)指定指针位于错误的函数类型上。那只会发生 如果回调函数有一个类
我正在尝试在我的 Swift SpriteKit 应用程序中使用 AVAudioSession。我遇到了奇怪的“未声明类型”问题。例如…… import AVFoundation var audioS
如果在编译期间(在实际编译和运行程序之前)其参数之一的值已知/未知,如何专门化模板函数? 我还不知道怎么做。 想法 1: #include #include int main(void){
我看到一些人的代码是这样的: while (!(baseType == typeof(Object))) { .... baseType = baseType.BaseType;
我正在尝试使用 GoColly 框架获取所有 HREF 链接,但是只允许任何域的 url 为根 URL 或子域(否路径)。我已经注释掉了我的 REGEXP。文件扩展名没有事情。我只是在“/”之后不想要
我有一个包含多个实体的数据库,特别是 Book 和 User。它们之间存在这样的 ManyToMany 关系: 书: @Entity @Table(name = "Books") public cla
如果我将范围的初始部分设置为 Range("A:A"),如何确保将整行传递给排序? 数据 id、fname、mname、lname、后缀、状态、位置、时区 通过在 id 中搜索起点和终点来选择范围。
我对kubernetes很陌生,而对于docker来说就不那么多了。 我一直在研究示例,但是我对自动缩放器(似乎无法缩放)感到困惑。 我在这里通过示例https://kubernetes.io/doc
我在 ChildWindow 中使用 SL Toolkit 5 中的 BusyIndicator 控件。 在某些解决方案中,它可以工作,但在其他解决方案中,使用完全相同的代码(至少看起来),我在运
我是一名优秀的程序员,十分优秀!