@@ -684,7 +684,7 @@ Predicting with trained model:
684684
685685**Usage Example: **
686686
687- Example below uses LinearRegression Model on a small dataset .
687+ Example below uses LinearRegression Model using the command line .
688688
689689Let us take a simple example:
690690
@@ -704,43 +704,34 @@ Let us take a simple example:
704704| 5 | 11 | 1.2 | 60 |
705705+----------------------+------------+--------------+--------+
706706
707- .. code-block :: console
707+ First we create the files
708+
709+ .. literalinclude :: /../model/scikit/examples/lr/train_data.sh
710+
711+ .. literalinclude :: /../model/scikit/examples/lr/test_data.sh
712+
713+ Train the model
714+
715+ .. literalinclude :: /../model/scikit/examples/lr/train.sh
716+
717+ Assess accuracy
718+
719+ .. literalinclude :: /../model/scikit/examples/lr/accuracy.sh
720+
721+ Output:
722+
723+ .. code-block ::
708724
709- $ cat > train.csv << EOF
710- Years,Expertise,Trust,Salary
711- 0,1,0.2,10
712- 1,3,0.4,20
713- 2,5,0.6,30
714- 3,7,0.8,40
715- EOF
716- $ cat > test.csv << EOF
717- Years,Expertise,Trust,Salary
718- 4,9,1.0,50
719- 5,11,1.2,60
720- EOF
721- $ dffml train \
722- -model scikitlr \
723- -model-features Years:int:1 Expertise:int:1 Trust:float:1 \
724- -model-predict Salary:float:1 \
725- -sources f=csv \
726- -source-filename train.csv \
727- -log debug
728- $ dffml accuracy \
729- -model scikitlr \
730- -model-features Years:int:1 Expertise:int:1 Trust:float:1 \
731- -model-predict Salary:float:1 \
732- -sources f=csv \
733- -source-filename test.csv \
734- -log debug
735725 1.0
736- $ echo -e 'Years,Expertise,Trust\n6,13,1.4\n' | \
737- dffml predict all \
738- -model scikitlr \
739- -model-features Years:int:1 Expertise:int:1 Trust:float:1 \
740- -model-predict Salary:float:1 \
741- -sources f=csv \
742- -source-filename /dev/stdin \
743- -log debug
726+
727+ Make a prediction
728+
729+ .. literalinclude :: /../model/scikit/examples/lr/predict.sh
730+
731+ Output:
732+
733+ .. code-block :: json
734+
744735 [
745736 {
746737 "extra" : {},
@@ -749,46 +740,20 @@ Let us take a simple example:
749740 "Trust" : 1.4 ,
750741 "Years" : 6
751742 },
752- "last_updated": "2019-09-18T19:04:18Z",
743+ "key" : " 0" ,
744+ "last_updated" : " 2020-02-07T14:17:08Z" ,
753745 "prediction" : {
754- "confidence": 1.0,
755- "value": 70.00000000000001
756- },
757- "key": 0
746+ "Salary" : {
747+ "confidence" : 1.0 ,
748+ "value" : 70.13972055888223
749+ }
750+ }
758751 }
759752 ]
760753
761754 Example usage of Linear Regression Model using python API:
762755
763- .. code-block :: python
764-
765- from dffml import CSVSource, Features, DefFeature
766- from dffml.noasync import train, accuracy, predict
767- from dffml_model_scikit import LinearRegressionModel
768-
769- model = LinearRegressionModel(
770- features = Features(
771- DefFeature(" Years" , int , 1 ),
772- DefFeature(" Expertise" , int , 1 ),
773- DefFeature(" Trust" , float , 1 ),
774- ),
775- predict = DefFeature(" Salary" , int , 1 ),
776- )
777-
778- # Train the model
779- train(model, " train.csv" )
780-
781- # Assess accuracy (alternate way of specifying data source)
782- print (" Accuracy:" , accuracy(model, CSVSource(filename = " test.csv" )))
783-
784- # Make prediction
785- for i, features, prediction in predict(
786- model,
787- {" Years" : 6 , " Expertise" : 13 , " Trust" : 0.7 },
788- {" Years" : 7 , " Expertise" : 15 , " Trust" : 0.8 },
789- ):
790- features[" Salary" ] = prediction[" Salary" ][" value" ]
791- print (features)
756+ .. literalinclude :: /../model/scikit/examples/lr/lr.py
792757
793758Example below uses KMeans Clustering Model on a small randomly generated dataset.
794759
0 commit comments