机器学习中的主动学习实现

    科技2026-08-31  21

    机器学习中的主动学习实现

    思维。 想太多。 React。 (Thinking. Overthinking. Reacting.)

    Isn’t this a familiar cycle? I reckon, for the majority of us: ‘definitely YES’. Like most other things, this cycle too is a double-edged sword: In some scenarios, the outcome can be positive and useful, but in others, it can be damaging and may even turn against you. The latter is what all of us wish to avoid. To have a clear understanding of segregation of emotions is what I wanted to do, and this led me to make this machine learning (ML) program.

    这不是一个熟悉的周期吗? 我认为,对于我们大多数人来说:“肯定是”。 像大多数其他事物一样,此循环也是一把双刃剑:在某些情况下,结果可能是积极而有用的,但在另一些情况下,结果可能是有害的,甚至可能不利于您。 后者是我们所有人希望避免的。 我想做的是对情感隔离有一个清晰的了解,这促使我编写了机器学习(ML)程序。

    Quarantine has given me plenty of chances to explore myself, and having a check on my thoughts is one of them. I’m not a deep thinker, but every so often I see myself tangled in thoughts, and whenever this happens, I need a way to channelise them. Precisely this is what I did. The goal was to create a ML model which could analyse my thinking procedure. I did this using the KNN algorithm, which helped me to predict the emotions I should avoid and visualization techniques, which enabled me to project my feelings graphically, making it a lot easier for me to understand the entire picture all at once. So, this is how I did it :

    隔离给了我很多探索自我的机会,检查自己的想法就是其中之一。 我不是一个深思熟虑的人,但是每隔一段时间我就会发现自己陷入各种想法之中,每当发生这种情况时,我都需要一种引导它们的方法。 正是这就是我所做的。 目的是创建一个可以分析我的思维过程的ML模型。 我使用KNN算法进行了此操作,该算法帮助我预测了应该避免的情绪,并通过可视化技术使我能够以图形方式投射自己的感觉,这使我更容易一次了解整个图片。 所以,这就是我的做法:

    1. To start the ball rolling, I created a dataset of different thoughts.2. Used KNN algorithm.3. Used visualization techniques.4. Finally, I learned to segregate my thinking procedure.

    1.为了开始进行滚动,我创建了一个不同想法的数据集。 2 。 使用了KNN算法。 3 。 使用的可视化技术。 4 。 最后,我学会了隔离思考程序。

    (if you don’t feel like walking through the steps then directly skip to the results.)

    (如果您不想遍历所有步骤,请直接跳至结果。)

    “It taught me how a ML program, not just has the capability to predict specific tasks which a human can do easily, but it can also derive an in-depth analysis of the dataset. This might just be the zeroth step towards replicating intelligence but still, isn’t this so interesting. Perhaps, this is the reason why it is termed as Machine Learning.”

    “它教会了我一个ML程序如何不仅具有预测人类可以轻松完成的特定任务的能力,而且还可以得出对数据集的深入分析。 这可能只是迈向复制智能的第零步,但并不是那么有趣。 也许,这就是为什么它被称为机器学习的原因。”

    数据集的创建 (Creation of dataset)

    The dataset is created based on nine different thoughts (features): discouraging, sad, worthless, crying, anguish, confusing, happy, uplifting and determined. I have classified all these thoughts into three categories (labels): positive, negative and neutral. Also, I have scored each of those nine thoughts or features on a scale of 1–10, based on the labels. In this way, I created a total of 150 cases. Below is a picture of how the first few rows of the dataset look:

    该数据集是基于九种不同的思想(特征)创建的:沮丧,悲伤,一文不值,哭泣,痛苦,困惑,快乐,振奋和坚定。 我将所有这些思想分为三类(标签):正面,负面和中立。 另外,根据标签,我对这9个想法或特征均按1-10的标准进行了评分。 这样,我总共创建了150个案例。 以下是数据集前几行的外观图:

    Image source: Author. 图片来源:作者。

    使用KNN算法 (Using KNN algorithm)

    Before we plunge any further, it will be helpful first to get to know about some basic terminologies of ML for supervised learning:

    在我们进一步深入之前,先了解一些用于监督学习的ML的基本术语将是有帮助的:

    To train, test and evaluate a model, we use a set of cases.

    为了训练,测试和评估模型,我们使用了一系列案例。

    These cases include features related to the model and a label value.

    这些情况包括与模型有关的特征和标签值。

    The features are the values which are used as a base to train any algorithm.

    特征是用作训练任何算法的基础的值。

    Once the training part is over, the algorithm is then able to predict the correct label values for the test features.

    训练部分结束后,算法便可以预测测试功能的正确标签值。

    The goal is to predict the label correctly. To check this, the accuracy of the trained algorithm should be high. If not, then the error between the predicted value of the label and the original label should be minimised.

    目的是正确预测标签。 为了检查这一点,训练算法的准确性应该很高。 如果不是,则标签的预测值和原始标签之间的误差应最小化。

    With this basic knowledge, let us understand the KNN (K-nearest neighbors) algorithm. KNN comes under supervised ML. The ‘K’ is a value for the number of points, nearest to the particular point which needs to be classified (e.g., K=1,2,3, etc.). Look at this diagram below for a better understanding.

    有了这些基本知识,让我们了解KNN(K最近邻)算法。 KNN属于受监督的ML。 “ K”是最接近需要分类的特定点的点数的值(例如,K = 1,2,3等)。 请看下面的图表,以更好地理解。

    Image source: Author. 图片来源:作者。

    In the first case, the KNN will classify the ‘?’ case as the green star since it is nearest to it. Similarly, in the second case, the KNN will classify the ‘?’ case as the yellow triangle since those triangles are the closest majority cases. For calculating this closeness between the new case and the known cases, any distance function can be used, e.g. Euclidean, Minkowski, etc. Therefore it is known as nearest neighbors. In this way, the KNN algorithm classifies a new case.

    在第一种情况下,KNN将对“?”进行分类案例,因为它离绿色星最近。 同样,在第二种情况下,KNN将对“?”进行分类case表示为黄色三角形,因为这些三角形是最接近的多数情况。 为了计算新案例与已知案例之间的紧密度,可以使用任何距离函数,例如欧几里得,明可夫斯基等。因此,它被称为最近邻居。 这样,KNN算法对新情况进行了分类。

    In this particular modal, KNN has the job to predict the class of different thoughts correctly. After performing all the data preprocessing steps, I applied the KNN algorithm on the data and then calculated the accuracy, which came out to be 98.6%. Below is a code snippet which shows the same:

    在这种特定模式中,KNN可以正确预测不同思想的类别。 完成所有数据预处理步骤后,我对数据应用了KNN算法,然后计算出准确度,得出的准确度为98.6%。 以下是显示相同内容的代码段:

    Image source: Author. 图片来源:作者。

    使用可视化技术 (Using Visualization Techniques)

    I have used visualization of data for classification so that it is easier to understand through graphs to create a solution that predicts the thoughts I should avoid in the future to have a positive mindset. This technique will help me to segregate the label categories (positive, negative and neutral). For this purpose, I have used ‘box plots’.

    我已经使用数据可视化进行分类,以便通过图形更易于理解,从而创建了一种解决方案,该解决方案可以预测我将来应该避免采用的积极思维方式。 此技术将帮助我隔离标签类别(正,负和中性)。 为此,我使用了“箱形图”。

    结果: (Results :)

    KNN algorithm graphs. (Image source: Author.) KNN算法图。 (图片来源:作者。) Image source: Author. 图片来源:作者。

    The graphs that KNN generated shows the following:

    KNN生成的图形显示以下内容:

    -Discouraging: The algorithm classified this feature as negative, which is right and obvious. But the noteworthy point is that there is a slight overlap between negative and neutral thoughts. Also, the margin between positive and negative is very minute. Which signifies the fact that discouraging thoughts somewhat have the power to motivate oneself to have a positive outcome. But all things considered, it is classified under a negative label.

    -Discouraging :该算法将该功能归类为负面,这是正确且显而易见的。 但是值得注意的是,消极思想和中立思想之间有轻微的重叠。 同样,正负之间的余量非常小。 这表明一个事实,即令人沮丧的思想在某种程度上具有激励自己取得积极成果的能力。 但是考虑到所有因素,它被归类为负面标签。

    -Confusing: This result amused me. The algorithm labelled it as positive. Before this analysis, I used to avoid any confusing idea. Maybe the fact that these thoughts are stirring has to do something with a positive outcome. Perhaps they give us time to gauge both the positive and negative side of the situation to be astute.

    令人困惑的结果该算法将其标记为肯定。 在进行此分析之前,我曾经避免过任何令人困惑的想法。 也许这些想法在激荡,这一事实一定会带来积极的结果。 也许它们给了我们时间来衡量形势的好与坏。

    -Sad: Unmistakably, this thought is bound to have a negative outcome.

    -Sad :无疑,这种想法必然会带来负面结果。

    -Worthless: There are times when people have random thoughts wobbling in their heads. They have no rhyme or reason to them. For me, this algorithm classified these thoughts as neutral.

    -无情:有时人们的脑海中会晃动随机的想法。 他们没有韵律或理由。 对我而言,此算法将这些想法归类为中立。

    -Crying: Akin to the sad feature, this feature too, is classified as negative. Although I thought that it might also have a neutral effect because crying can help to balance emotions. But if we only consider the neutral and positive label then from its graph, it is likely to be classified as positive than neutral. Overall it triggers a negative mood.

    -哭泣:类似于可悲的功能,该功能也归为负面。 尽管我认为它可能也具有中立作用,因为哭泣可以帮助平衡情绪。 但是,如果我们仅考虑中性和阳性标签,则从其图表中,很可能将其归类为阳性而不是中性。 总体而言,它会引发负面情绪。

    -Anguish: According to what the model predicts, it is the foremost feature which is the cause of a bad mood. Consequently, being highly negative.

    -烦恼:根据模型预测,这是导致心情不好的最重要特征。 因此,是高度负面的。

    -Uplifting: KNN predicted this feature beneficial to me. However, the graph shows a slight overlap between neutral and negative mood. Besides, If we only consider these two labels then strikingly, the negative label has a more significant impact than the neutral one.

    -令人振奋: KNN预测此功能对我有益。 但是,该图显示中性和负面情绪略有重叠。 此外,如果我们仅考虑这两个标签,那么引人注目的是,负面标签的影响要比中性标签大得多。

    -Determined: This feature has an exciting plot. The results have hardly any difference between them. It is hard to interpret it at once. But this can be much easily understood using its box plot.

    -确定:此功能具有令人兴奋的情节。 结果之间几乎没有任何区别。 很难立即解释它。 但是,使用箱形图可以很容易地理解这一点。

    Box plot graphs. (Image source: Author.) 箱形图。 (图片来源:作者。)

    These box plots provide a thorough graphical representation, and they are easy to read too, as they give a clear differentiation of the three different moods or labels based on the features or thoughts. More or less, it depicts the same results as the KNN graphs. However, it provides a better explanation for:

    这些箱形图提供了完整的图形表示,并且易于阅读,因为它们可以根据特征或思想对三种不同的心情或标签进行清晰区分。 或多或少,它描绘的结果与KNN图相同。 但是,它为以下问题提供了更好的解释:

    -Determined: Even though it may look like this feature distinctly will be classified as positive but based on the data, the KNN graph shows a similarity among all three labels, which, in a way might be misleading. So, if you look at its box plot, you will notice that the positive outcome is just a bit higher than the other two. Hence this feature is categorized as a positive label.

    -确定:尽管看起来该功能显然将被归类为正,但基于数据,KNN图显示了所有三个标签之间的相似性,这在某种程度上可能会引起误解。 因此,如果看一下它的箱形图,您会注意到,积极的结果只比其他两个要好一点。 因此,此功能归为肯定标签。

    -Happy: Undeniably, this feature classifies as a positive label. However, its quartile for neutral is much more than that of positive, and if we only consider neutral and negative, then neutral is higher than the two.

    -快乐:不可否认,此功能归为肯定标签。 但是,它对中性的四分位数远大于正数,如果仅考虑中性和负数,则中性要高于两者。

    结论 (Conclusion)

    This was an exciting project. At first, I thought that I would just get a simple classification result which would be quite obvious, but after completing this project, I realised that there is more to this classification. It taught me how an ML program, not just has the capability to predict specific tasks which a human can do easily, but it can also derive an in-depth analysis of the dataset. This might just be the zeroth step towards replicating intelligence but still, isn’t this so interesting. Perhaps, this is the reason why it is termed as ‘Machine Learning’.

    这是一个令人兴奋的项目。 起初,我以为我会得到一个简单的分类结果,这将是显而易见的,但是在完成该项目之后,我意识到该分类还有更多的东西。 它教会了我一个ML程序如何不仅具有预测人类可以轻松完成的特定任务的能力,而且还可以对数据集进行深入的分析。 这可能只是迈向复制智能的第零步,但并不是那么有趣。 也许,这就是为什么它被称为“机器学习”的原因。

    Image source: Author. 图片来源:作者。

    翻译自: https://medium.com/swlh/how-i-used-machine-learning-to-help-achieve-mindfulness-d4b21f707b66

    机器学习中的主动学习实现

    相关资源:微信小程序源码-合集6.rar
    Processed: 0.013, SQL: 9