Loading...

vastorbit.machine_learning.vast.ensemble.IsolationForest.predict

IsolationForest.predict(vdf: Annotated[str | VastFrame, ''], X: Annotated[str | list[str], 'STRING representing one column or a list of columns'] | None = None, name: str | None = None, cutoff: Annotated[int | float | Decimal, 'Python Numbers'] = 0.7, contamination: Annotated[int | float | Decimal, 'Python Numbers'] | None = None, inplace: bool = True) VastFrame

Predicts using the input relation.

Parameters:
  • vdf (SQLRelation) – Object to use for the prediction. You can specify a customized relation if it is enclosed with an alias. For example, (SELECT 1) x is valid, whereas (SELECT 1) and SELECT 1 are invalid.

  • X (list, optional) – list of columns used to deploy the models. If empty, the model predictors are used.

  • name (str, optional) – Name of the additional VastColumn. If empty, a name is generated.

  • cutoff (PythonNumber, optional) – float in the range (0.0, 1.0), specifies the threshold that determines if a data point is an anomaly. If the anomaly_score for a data point is greater than or equal to the cutfoff, the data point is marked as an anomaly.

  • contamination (PythonNumber, optional) – float in the range (0, 1), the approximate ratio of data points in the training data that should be labeled as anomalous. If this parameter is specified, the cutoff parameter is ignored.

  • inplace (bool, optional) – If True, the prediction is added to the VastFrame.

Returns:

the input object.

Return type:

VastFrame

Examples

We import vastorbit:

import vastorbit as vo

For this example, we will use the winequality dataset.

import vastorbit.datasets as vod

data = vod.load_winequality()
123
fixed_acidity
Decimal(6, 3)
123
volatile_acidity
Decimal(7, 4)
123
citric_acid
Decimal(6, 3)
123
residual_sugar
Decimal(7, 3)
123
chlorides
Double
123
free_sulfur_dioxide
Decimal(7, 2)
123
total_sulfur_dioxide
Decimal(7, 2)
123
density
Double
123
ph
Decimal(6, 3)
123
sulphates
Decimal(6, 3)
123
alcohol
Double
123
quality
Integer
123
good
Integer
Abc
color
Varchar(20)
16.30.670.4812.60.05257.0222.00.99793.170.529.360white
27.40.40.295.40.04431.0122.00.9943.30.511.181white
37.10.260.312.20.04429.0128.00.99373.340.6410.981white
49.00.310.486.60.04311.073.00.99382.90.3811.650white
56.30.390.246.90.0699.0117.00.99423.150.3510.240white
68.20.220.366.80.03412.090.00.99443.010.3810.581white
77.10.190.283.60.03316.078.00.9932.910.7811.460white
87.30.250.3613.10.0535.0200.00.99863.040.468.971white
97.90.20.341.20.0429.0118.00.99323.140.4110.660white
107.10.260.325.90.03739.097.00.99343.310.411.660white
117.00.20.345.70.03532.083.00.99283.190.4611.560white
126.90.30.334.10.03526.0155.00.99253.250.7912.381white
138.10.290.497.10.04222.0124.00.99443.140.4110.860white
145.80.170.31.40.03755.0130.00.99093.290.3811.360white
155.90.4150.020.80.03822.063.00.99323.360.369.350white
166.60.230.261.30.04516.0128.00.99343.360.610.060white
178.60.550.3515.550.05735.5366.51.00013.040.6311.030white
186.90.350.741.00.04418.0132.00.9923.130.5510.250white
197.60.140.741.60.0427.0103.00.99163.070.410.871white
209.20.280.4911.80.04229.0137.00.9983.10.3410.140white
216.20.180.494.50.04717.090.00.99193.270.3711.660white
225.30.1650.241.10.05125.0105.00.99253.320.479.150white
239.80.250.7410.00.05636.0225.00.99773.060.4310.040white
248.10.290.497.10.04222.0124.00.99443.140.4110.860white
256.80.220.490.90.05226.0128.00.9913.250.3511.460white
267.20.220.491.00.04534.0140.00.993.050.3412.760white
277.40.250.491.10.04235.0156.00.99173.130.5511.350white
288.20.180.491.10.03328.081.00.99233.00.6810.471white
296.10.220.491.50.05118.087.00.99283.30.469.650white
307.00.390.241.00.0488.0119.00.99233.00.3110.140white
316.10.220.491.50.05118.087.00.99283.30.469.650white
326.50.360.492.90.0316.094.00.99023.10.4912.171white
337.10.290.491.20.03132.099.00.98933.070.3312.260white
347.40.250.491.10.04235.0156.00.99173.130.5511.350white
356.90.230.2414.20.05319.094.00.99823.170.59.650white
368.50.560.7417.850.05151.0243.01.00052.990.79.250white
378.20.180.491.10.03328.081.00.99233.00.6810.471white
386.30.230.497.10.0567.0210.00.99513.230.349.550white
396.10.250.497.60.05267.0226.00.99563.160.478.950white
407.20.260.7413.60.0556.0162.00.9983.030.448.850white
417.20.310.241.40.05717.0117.00.99283.160.3510.550white
428.00.250.491.20.06127.0117.00.99383.080.349.450white
437.00.180.495.30.0434.0125.00.99143.240.412.260white
447.80.430.4913.00.03337.0158.00.99553.140.3511.360white
458.30.20.744.450.04433.0130.00.99243.250.4212.260white
466.30.270.491.20.06335.092.00.99113.380.4212.260white
477.40.160.491.20.05518.0150.00.99173.230.4711.260white
487.40.160.491.20.05518.0150.00.99173.230.4711.260white
496.90.190.496.60.03649.0172.00.99323.20.2711.560white
507.80.430.4913.00.03337.0158.00.99553.140.3511.360white
517.20.40.491.10.04811.0138.00.99293.010.429.350white
527.80.430.4913.00.03337.0158.00.99553.140.3511.360white
537.60.520.4914.00.03437.0156.00.99583.140.3811.871white
548.30.210.4919.80.05450.0231.01.00122.990.549.250white
556.90.340.7411.20.06944.0150.00.99683.00.819.250white
566.30.270.491.20.06335.092.00.99113.380.4212.260white
578.30.20.744.450.04433.0130.00.99243.250.4212.260white
587.10.220.742.70.04442.0144.00.9913.310.4112.260white
597.90.110.494.50.04827.0133.00.99463.240.4210.660white
608.50.170.743.60.0529.0128.00.99283.280.412.460white
616.40.1450.495.40.04854.0164.00.99463.560.4410.860white
627.40.160.491.20.05518.0150.00.99173.230.4711.260white
638.30.190.491.20.05111.0137.00.99183.060.4611.060white
648.00.440.499.10.03146.0151.00.99263.160.2712.781white
657.00.20.740.80.04419.0163.00.99313.460.5310.250white
666.90.190.496.60.03649.0172.00.99323.20.2711.560white
677.10.250.493.00.0330.096.00.99033.130.3912.371white
686.50.240.241.60.04615.060.00.99283.190.399.850white
697.20.40.491.10.04811.0138.00.99293.010.429.350white
707.60.520.4914.00.03437.0156.00.99583.140.3811.871white
717.80.430.4913.00.03337.0158.00.99553.140.3511.360white
727.80.210.491.350.0526.048.00.99113.150.2811.450white
737.00.20.495.90.03839.0128.00.99383.210.4810.860white
746.90.250.243.60.05713.085.00.99422.990.489.540white
757.20.080.491.30.0518.0148.00.99453.460.4410.260white
767.10.850.498.70.02840.0184.00.99623.220.3610.750white
777.60.510.241.20.0410.0104.00.9923.050.2910.860white
787.90.220.244.60.04439.0159.00.99272.990.2811.560white
797.70.160.492.00.05620.0124.00.99483.320.4910.760white
807.20.080.491.30.0518.0148.00.99453.460.4410.260white
816.60.250.241.70.04826.0124.00.99423.370.610.160white
826.70.160.492.40.04657.0187.00.99523.620.8110.460white
836.90.250.243.60.05713.085.00.99422.990.489.540white
847.50.320.244.60.0538.0134.00.99583.140.59.130white
857.40.280.491.50.03420.0126.00.99182.980.3910.660white
866.20.150.490.90.03317.051.00.99323.30.79.460white
876.70.250.7419.40.05444.0169.01.00043.510.459.860white
886.50.260.7413.30.04468.0224.00.99723.180.549.560white
897.90.160.7417.850.03752.0187.00.99982.990.419.350white
905.60.1850.491.10.0328.0117.00.99183.550.4510.360white
917.50.20.491.30.0318.097.00.99183.060.6211.150white
928.00.30.499.40.04647.0188.00.99643.140.4810.050white
938.00.340.499.00.03339.0180.00.99363.130.3812.381white
947.70.350.498.650.03342.0186.00.99313.140.3812.481white
957.60.290.499.60.0345.0197.00.99383.130.3812.371white
966.70.620.241.10.0396.062.00.99343.410.3210.450white
976.80.270.491.20.04435.0126.00.993.130.4812.171white
987.70.270.491.80.04123.086.00.99143.160.4212.560white
996.70.510.242.10.04314.0155.00.99043.220.613.060white
1007.40.190.499.30.0326.0132.00.9942.990.3211.071white
Rows: 1-100 | Columns: 14

We import the IsolationForest model:

from vastorbit.machine_learning.vast import IsolationForest

Then we can create the model:

model = IsolationForest(
    n_estimators = 5,
)

We can now fit the model:

model.fit(data, X = ["density", "sulphates"])

Prediction is straight-forward:

model.predict(data, ["density", "sulphates"])
123
fixed_acidity
Decimal(6, 3)
123
volatile_acidity
Decimal(7, 4)
123
citric_acid
Decimal(6, 3)
123
residual_sugar
Decimal(7, 3)
123
chlorides
Double
123
free_sulfur_dioxide
Decimal(7, 2)
123
total_sulfur_dioxide
Decimal(7, 2)
123
density
Double
123
ph
Decimal(6, 3)
123
sulphates
Decimal(6, 3)
123
alcohol
Double
123
quality
Integer
123
good
Integer
Abc
color
Varchar(20)
123
isolationforest_default_vastorbit_tmp_isolationforest_memory_admin_f8679d10754811f1becdea8c65480234_
Integer
16.30.670.4812.60.05257.0222.00.99793.170.529.360white0
27.40.40.295.40.04431.0122.00.9943.30.511.181white0
37.10.260.312.20.04429.0128.00.99373.340.6410.981white0
49.00.310.486.60.04311.073.00.99382.90.3811.650white0
56.30.390.246.90.0699.0117.00.99423.150.3510.240white0
68.20.220.366.80.03412.090.00.99443.010.3810.581white0
77.10.190.283.60.03316.078.00.9932.910.7811.460white0
87.30.250.3613.10.0535.0200.00.99863.040.468.971white0
97.90.20.341.20.0429.0118.00.99323.140.4110.660white0
107.10.260.325.90.03739.097.00.99343.310.411.660white0
117.00.20.345.70.03532.083.00.99283.190.4611.560white0
126.90.30.334.10.03526.0155.00.99253.250.7912.381white0
138.10.290.497.10.04222.0124.00.99443.140.4110.860white0
145.80.170.31.40.03755.0130.00.99093.290.3811.360white0
155.90.4150.020.80.03822.063.00.99323.360.369.350white0
166.60.230.261.30.04516.0128.00.99343.360.610.060white0
178.60.550.3515.550.05735.5366.51.00013.040.6311.030white0
186.90.350.741.00.04418.0132.00.9923.130.5510.250white0
197.60.140.741.60.0427.0103.00.99163.070.410.871white0
209.20.280.4911.80.04229.0137.00.9983.10.3410.140white0
216.20.180.494.50.04717.090.00.99193.270.3711.660white0
225.30.1650.241.10.05125.0105.00.99253.320.479.150white0
239.80.250.7410.00.05636.0225.00.99773.060.4310.040white0
248.10.290.497.10.04222.0124.00.99443.140.4110.860white0
256.80.220.490.90.05226.0128.00.9913.250.3511.460white0
267.20.220.491.00.04534.0140.00.993.050.3412.760white0
277.40.250.491.10.04235.0156.00.99173.130.5511.350white0
288.20.180.491.10.03328.081.00.99233.00.6810.471white0
296.10.220.491.50.05118.087.00.99283.30.469.650white0
307.00.390.241.00.0488.0119.00.99233.00.3110.140white0
316.10.220.491.50.05118.087.00.99283.30.469.650white0
326.50.360.492.90.0316.094.00.99023.10.4912.171white0
337.10.290.491.20.03132.099.00.98933.070.3312.260white0
347.40.250.491.10.04235.0156.00.99173.130.5511.350white0
356.90.230.2414.20.05319.094.00.99823.170.59.650white0
368.50.560.7417.850.05151.0243.01.00052.990.79.250white0
378.20.180.491.10.03328.081.00.99233.00.6810.471white0
386.30.230.497.10.0567.0210.00.99513.230.349.550white0
396.10.250.497.60.05267.0226.00.99563.160.478.950white0
407.20.260.7413.60.0556.0162.00.9983.030.448.850white0
417.20.310.241.40.05717.0117.00.99283.160.3510.550white0
428.00.250.491.20.06127.0117.00.99383.080.349.450white0
437.00.180.495.30.0434.0125.00.99143.240.412.260white0
447.80.430.4913.00.03337.0158.00.99553.140.3511.360white0
458.30.20.744.450.04433.0130.00.99243.250.4212.260white0
466.30.270.491.20.06335.092.00.99113.380.4212.260white0
477.40.160.491.20.05518.0150.00.99173.230.4711.260white0
487.40.160.491.20.05518.0150.00.99173.230.4711.260white0
496.90.190.496.60.03649.0172.00.99323.20.2711.560white0
507.80.430.4913.00.03337.0158.00.99553.140.3511.360white0
517.20.40.491.10.04811.0138.00.99293.010.429.350white0
527.80.430.4913.00.03337.0158.00.99553.140.3511.360white0
537.60.520.4914.00.03437.0156.00.99583.140.3811.871white0
548.30.210.4919.80.05450.0231.01.00122.990.549.250white0
556.90.340.7411.20.06944.0150.00.99683.00.819.250white0
566.30.270.491.20.06335.092.00.99113.380.4212.260white0
578.30.20.744.450.04433.0130.00.99243.250.4212.260white0
587.10.220.742.70.04442.0144.00.9913.310.4112.260white0
597.90.110.494.50.04827.0133.00.99463.240.4210.660white0
608.50.170.743.60.0529.0128.00.99283.280.412.460white0
616.40.1450.495.40.04854.0164.00.99463.560.4410.860white0
627.40.160.491.20.05518.0150.00.99173.230.4711.260white0
638.30.190.491.20.05111.0137.00.99183.060.4611.060white0
648.00.440.499.10.03146.0151.00.99263.160.2712.781white0
657.00.20.740.80.04419.0163.00.99313.460.5310.250white0
666.90.190.496.60.03649.0172.00.99323.20.2711.560white0
677.10.250.493.00.0330.096.00.99033.130.3912.371white0
686.50.240.241.60.04615.060.00.99283.190.399.850white0
697.20.40.491.10.04811.0138.00.99293.010.429.350white0
707.60.520.4914.00.03437.0156.00.99583.140.3811.871white0
717.80.430.4913.00.03337.0158.00.99553.140.3511.360white0
727.80.210.491.350.0526.048.00.99113.150.2811.450white0
737.00.20.495.90.03839.0128.00.99383.210.4810.860white0
746.90.250.243.60.05713.085.00.99422.990.489.540white0
757.20.080.491.30.0518.0148.00.99453.460.4410.260white0
767.10.850.498.70.02840.0184.00.99623.220.3610.750white0
777.60.510.241.20.0410.0104.00.9923.050.2910.860white0
787.90.220.244.60.04439.0159.00.99272.990.2811.560white0
797.70.160.492.00.05620.0124.00.99483.320.4910.760white0
807.20.080.491.30.0518.0148.00.99453.460.4410.260white0
816.60.250.241.70.04826.0124.00.99423.370.610.160white0
826.70.160.492.40.04657.0187.00.99523.620.8110.460white0
836.90.250.243.60.05713.085.00.99422.990.489.540white0
847.50.320.244.60.0538.0134.00.99583.140.59.130white0
857.40.280.491.50.03420.0126.00.99182.980.3910.660white0
866.20.150.490.90.03317.051.00.99323.30.79.460white0
876.70.250.7419.40.05444.0169.01.00043.510.459.860white0
886.50.260.7413.30.04468.0224.00.99723.180.549.560white0
897.90.160.7417.850.03752.0187.00.99982.990.419.350white0
905.60.1850.491.10.0328.0117.00.99183.550.4510.360white0
917.50.20.491.30.0318.097.00.99183.060.6211.150white0
928.00.30.499.40.04647.0188.00.99643.140.4810.050white0
938.00.340.499.00.03339.0180.00.99363.130.3812.381white0
947.70.350.498.650.03342.0186.00.99313.140.3812.481white0
957.60.290.499.60.0345.0197.00.99383.130.3812.371white0
966.70.620.241.10.0396.062.00.99343.410.3210.450white0
976.80.270.491.20.04435.0126.00.993.130.4812.171white0
987.70.270.491.80.04123.086.00.99143.160.4212.560white0
996.70.510.242.10.04314.0155.00.99043.220.613.060white0
1007.40.190.499.30.0326.0132.00.9942.990.3211.071white0
Rows: 1-100 | Columns: 15

Note

Refer to IsolationForest for more information about the different methods and usages.