⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sample.cs

📁 It s the kNN or else named k-Nearest Neabours algorythm, realized by the tools of Visual Studio deve
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace kNN
{
    class Sample
    {

        private ArrayList items;
        private string class_;

        public Sample(ArrayList sample, int target)
        {
            this.class_ = sample[target].ToString();
            this.items = sample.Clone() as ArrayList;
            this.items.RemoveAt(target);
            TransferItems();

        }
        public void TransferItems()
        {
            ArrayList temp = new ArrayList();
            foreach (string item in this.items)
            {
                string[] q = (item.Split('.'));
                if (q.Length > 1)
                {
                    string a = q[0].ToString() + "," + q[1].ToString();
                    temp.Add(a);
                }
                else temp.Add(item);
                this.items = temp;
            }
        }

        public double CountDistance(Sample neighbour)
        {
            
            double d = 0;
            for (int i = 0; i < this.items.Count; i++)
            {
                double temp1=Convert.ToDouble(this.items[i]);
                    double temp2 = Convert.ToDouble(neighbour.GetItems()[i]);
                d += Math.Pow((temp1-temp2), 2);
            }
            return Math.Sqrt(d);
        }



        public ArrayList GetItems()
        {
            return this.items;
        }
        public string GetClass()
        {
            return this.class_;
        }
        public Sample GetSample()
        {
            return this;
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -