-1

我有这两个课

public class Iris_Setosa {

private double sepal_length;
private double sepal_width;
private double petal_length;
private double petal_width;


//Constractor
public Iris_Setosa(double s_length,double s_width,double p_length,double p_width)
{
    this.sepal_length=s_length;
    this.sepal_width=s_width;
    this.petal_length=p_length;
    this.petal_width=p_width;
}

public double sepal_length()
{
    return this.sepal_length;
}

public double sepal_width()
{
    return this.sepal_width;
}

public double petal_length()
{
    return this.petal_length;
}

public double petal_width()
{
    return this.petal_width;
}
}

public class Iris_Versicolour {
private double sepal_length;
private double sepal_width;
private double petal_length;
private double petal_width;


//Constractor
public Iris_Versicolour(double s_length,double s_width,double p_length,double p_width)
{
    this.sepal_length=s_length;
    this.sepal_width=s_width;
    this.petal_length=p_length;
    this.petal_width=p_width;

}


public double sepal_length()
{
    return this.sepal_length;
}

public double sepal_width()
{
    return this.sepal_width;
}

public double petal_length()
{
    return this.petal_length;
}

public double petal_width()
{
    return this.petal_width;
}
}

我定义了两个向量并设置数据:

Vector <Iris_Setosa> I_Setosa = new Vector <Iris_Setosa>();
Vector <Iris_Versicolour> I_Versicolour = new Vector <Iris_Versicolouלr>();
//data
I_Setosa.add(new Iris_Setosa (4.6,3.4,1.4,0.3));
I_Setosa.add(new Iris_Setosa (5.4,3.9,1.7,0.4));
I_Versicolour.add(new Iris_Versicolour(6.4,3.2,4.5,1.5));
I_Versicolour.add(new Iris_Versicolour(6.9,3.1,4.9,1.5));
.......

我们如何将这两个向量分类在一起,以便被视为空间中的点?

4

1 回答 1

0

所以现在你有了一个新样本,s = [4.7, 3.3, 1.5, 0.5]

第一个快速而肮脏的方法是 1NN(K 最近邻,K=1)。在这种情况下,您将计算s和四个点中的每一个之间的欧几里得距离。
您会发现四个您的四个案例的距离分别为 5.93、6.40、6.94 和 7.12。在这种情况下,您选择第一个训练样本,因为它最接近,导致 I_Setosa 的预测。更具体地说,它与 Iris_Setosa (4.6,3.4,1.4,0.3) 最相似

希望这可以帮助

于 2013-06-11T21:22:57.310 回答