KNNClassifier / Regressor review

nix
Gerard 6 years ago
parent b2338ed9d9
commit d96dbb8791

@ -1,30 +1,29 @@
FluidKNNClassifier : FluidManipulationClient {
*new {|server|
var uid = UniqueID.next;
^super.new(server,uid)!?{|inst|inst.init(uid);inst}
}
var uid = UniqueID.next;
^super.new(server,uid)!?{|inst|inst.init(uid);inst}
}
init {|uid|
id = uid;
}
init {|uid|
id = uid;
}
fit{|dataset, labelset, action|
this.prSendMsg(\fit,[dataset.asSymbol, labelset.asSymbol], action);
}
fit{|dataset, labelset, action|
this.prSendMsg(\fit,[dataset.asSymbol, labelset.asSymbol], action);
}
predict{ |dataset, labelset, k, uniform = 0, action|
this.prSendMsg(\predict,
predict{|dataset, labelset, k, uniform = 0, action|
this.prSendMsg(\predict,
[dataset.asSymbol, labelset.asSymbol, k, uniform],
action);
}
}
predictPoint { |buffer, k, uniform = 0, action|
this.prSendMsg(\predictPoint,
[buffer.asUGenInput, k,uniform], action,
predictPoint {|buffer, k, uniform = 0, action|
this.prSendMsg(\predictPoint,
[buffer.asUGenInput, k, uniform], action,
[string(FluidMessageResponse,_,_)]
);
}
}

@ -1,29 +1,29 @@
FluidKNNRegressor : FluidManipulationClient {
*new {|server|
var uid = UniqueID.next;
^super.new(server,uid)!?{|inst|inst.init(uid);inst}
}
var uid = UniqueID.next;
^super.new(server,uid)!?{|inst|inst.init(uid);inst}
}
init {|uid|
id = uid;
}
init {|uid|
id = uid;
}
fit{|sourceDataset, targetDataset, action|
this.prSendMsg(\fit,
fit{|sourceDataset, targetDataset, action|
this.prSendMsg(\fit,
[sourceDataset.asSymbol, targetDataset.asSymbol],
action
);
}
}
predict{ |sourceDataset, targetDataset, k, uniform = 0, action|
this.prSendMsg(\predict,
predict{ |sourceDataset, targetDataset, k, uniform = 0, action|
this.prSendMsg(\predict,
[sourceDataset.asSymbol, targetDataset.asSymbol, k, uniform],
action);
}
}
predictPoint { |buffer, k, uniform = 0, action|
this.prSendMsg(\predictPoint, [buffer.asUGenInput, k,uniform], action,
predictPoint { |buffer, k, uniform = 0, action|
this.prSendMsg(\predictPoint, [buffer.asUGenInput, k, uniform], action,
[number(FluidMessageResponse,_,_)]);
}
}
}

@ -4,6 +4,8 @@ categories:: Classification, KNN
related:: Classes/FluidKNNRegressor, Classes/FluidDataSet, Classes/FluidLabelSet
DESCRIPTION::
A nearest-neighbor classifier using link::Classes/FluidKDTree:: . Each point is assigned the class that is most common among its nearest neighbors.
https://scikit-learn.org/stable/modules/neighbors.html#classification
CLASSMETHODS::
@ -15,7 +17,7 @@ The server to make the model on
INSTANCEMETHODS::
METHOD:: fit
Fit the model to a source link::Classes/FluidDataSet:: and a target link::Classes/FluidLabelSet:: . These need to be the sime size
Fit the model to a source link::Classes/FluidDataSet:: and a target link::Classes/FluidLabelSet::. These need to be the same size
ARGUMENT:: dataset
Source data
ARGUMENT:: labelset
@ -32,7 +34,7 @@ place to write labels
ARGUMENT:: k
the number of neighours to consider
ARGUMENT:: uniform
true / false: whether the neighbours shold be weighted by distance
true / false: whether the neighbours should be weighted by distance
ARGUMENT:: action
Run when done
@ -43,7 +45,7 @@ A data point
ARGUMENT:: k
Number of neighbours to consider
ARGUMENT:: uniform
true / false: whether the neighbours shold be weighted by distance
true / false: whether the neighbours should be weighted by distance (default) or uniformly
ARGUMENT:: action
Run when done, passes predicted label as argument

@ -4,6 +4,9 @@ categories:: Regression
related:: Classes/FluidKNNClassifier, Classes/FluidDataSet
DESCRIPTION::
A nearest-neighbor regressor. A continuous value is predicted for each point as the (weighted) average value of its nearest neighbors.
https://scikit-learn.org/stable/modules/neighbors.html#regression
CLASSMETHODS::
@ -15,7 +18,7 @@ The server to run this model on.
INSTANCEMETHODS::
METHOD:: fit
Map a source link::Classes/FluidDataSet:: to a target; they must be the same size, but can have different dimensionality
Map a source link::Classes/FluidDataSet:: to a one-dimensional target; both datasets need to have the same number of points.
ARGUMENT:: sourceDataset
Source data
ARGUMENT:: targetDataset
@ -44,7 +47,7 @@ data point
ARGUMENT:: k
number of neigbours to consider in mapping, min 1
ARGUMENT:: uniform
Whether to weight neighbours by distance when producing new point
Whether the neighbours should be weighted by distance (default) or uniformly
ARGUMENT:: action
Run when done
@ -105,4 +108,4 @@ fork{
)
//We should see a single cycle of a chirp
~outputdata.plot;
::
::

Loading…
Cancel
Save