chore(boards): 调整mixpy下sklearn模块
This commit is contained in:
36
boards/default_src/python_pyodide/blocks/sklearn.js
Normal file
36
boards/default_src/python_pyodide/blocks/sklearn.js
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @typedef {import('@mixly/python-mixpy').PythonMixpySKLearnBlocks} PythonMixpySKLearnBlocks
|
||||
*/
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
const SKLEARN_HUE = 80;
|
||||
|
||||
|
||||
/**
|
||||
* @override Override {@link PythonMixpySKLearnBlocks.sklearn_LinearRegression}
|
||||
*/
|
||||
//sklearn 初始化线性回归
|
||||
export const sklearn_LinearRegression = {
|
||||
init: function () {
|
||||
this.appendDummyInput()
|
||||
.appendField('sklearn ' + Blockly.Msg.SKLEARN_LINEARREGRESSION_INIT);
|
||||
this.appendValueInput('model_name')
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.MODEL_NAME);
|
||||
this.appendValueInput('fit_intercept')
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.SKLEARN_CALCULATE_MODEL_INTERRUPT);
|
||||
this.appendValueInput('n_jobs')
|
||||
.setCheck(null)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(Blockly.Msg.SKLEARN_THREADS);
|
||||
this.setInputsInline(false);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setColour(SKLEARN_HUE);
|
||||
this.setTooltip('');
|
||||
this.setHelpUrl('');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import * as PythonPyodideSKLearnBlocks from './blocks/sklearn';
|
||||
import * as PythonPyodideSKLearnGenerators from './generators/sklearn';
|
||||
|
||||
export {
|
||||
PythonPyodideSKLearnBlocks,
|
||||
PythonPyodideSKLearnGenerators
|
||||
};
|
||||
13
boards/default_src/python_pyodide/generators/sklearn.js
Normal file
13
boards/default_src/python_pyodide/generators/sklearn.js
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* @typedef {import('@mixly/python-mixpy').PythonMixpySKLearnGenerators} PythonMixpySKLearnGenerators
|
||||
*/
|
||||
|
||||
// sklearn 初始化线性回归
|
||||
export const sklearn_LinearRegression = function (_, generator) {
|
||||
const value_model_name = generator.valueToCode(this, 'model_name', generator.ORDER_ATOMIC) || 'model';
|
||||
const value_fit_intercept = generator.valueToCode(this, 'fit_intercept', generator.ORDER_ATOMIC) || 'True';
|
||||
const value_n_jobs = generator.valueToCode(this, 'n_jobs', generator.ORDER_ATOMIC) || 'None';
|
||||
generator.definitions_['import_sklearn_linear_model'] = 'from sklearn.linear_model import LinearRegression';
|
||||
const code = value_model_name + ' = LinearRegression(fit_intercept=' + value_fit_intercept + ', n_jobs=' + value_n_jobs + ')\n';
|
||||
return code;
|
||||
}
|
||||
@@ -67,6 +67,11 @@ import {
|
||||
PythonMixpyTurtleGenerators
|
||||
} from '@mixly/python-mixpy';
|
||||
|
||||
import {
|
||||
PythonPyodideSKLearnBlocks,
|
||||
PythonPyodideSKLearnGenerators
|
||||
} from './';
|
||||
|
||||
import './others/loader';
|
||||
|
||||
import './css/color_mixpy_python_advance.css';
|
||||
@@ -108,6 +113,7 @@ Object.assign(
|
||||
PythonMixpySKLearnBlocks,
|
||||
PythonMixpySystemBlocks,
|
||||
PythonMixpyTurtleBlocks,
|
||||
PythonPyodideSKLearnBlocks
|
||||
);
|
||||
|
||||
Object.assign(
|
||||
@@ -139,5 +145,6 @@ Object.assign(
|
||||
PythonMixpySerialGenerators,
|
||||
PythonMixpySKLearnGenerators,
|
||||
PythonMixpySystemGenerators,
|
||||
PythonMixpyTurtleGenerators
|
||||
PythonMixpyTurtleGenerators,
|
||||
PythonPyodideSKLearnGenerators
|
||||
);
|
||||
@@ -3467,7 +3467,7 @@
|
||||
<block type="sklearn_train_test_split">
|
||||
<value name="train_data">
|
||||
<shadow type="variables_get">
|
||||
<field name="VAR">iris_X</field>
|
||||
<field name="VAR">iris_x</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="train_target">
|
||||
@@ -3495,11 +3495,6 @@
|
||||
<field name="BOOL">TRUE</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="normalize">
|
||||
<shadow type="logic_boolean">
|
||||
<field name="BOOL">FALSE</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="n_jobs">
|
||||
<shadow type="logic_null"></shadow>
|
||||
</value>
|
||||
@@ -3588,7 +3583,7 @@
|
||||
</value>
|
||||
<value name="train_data">
|
||||
<shadow type="variables_get">
|
||||
<field name="VAR">X</field>
|
||||
<field name="VAR">x</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
@@ -3645,7 +3640,7 @@
|
||||
</value>
|
||||
<value name="train_data">
|
||||
<shadow type="variables_get">
|
||||
<field name="VAR">X</field>
|
||||
<field name="VAR">x</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
@@ -3657,7 +3652,7 @@
|
||||
</value>
|
||||
<value name="train_data">
|
||||
<shadow type="variables_get">
|
||||
<field name="VAR">X_train</field>
|
||||
<field name="VAR">x_train</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="train_target">
|
||||
@@ -3674,7 +3669,7 @@
|
||||
</value>
|
||||
<value name="train_data">
|
||||
<shadow type="variables_get">
|
||||
<field name="VAR">X_test</field>
|
||||
<field name="VAR">x_test</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="train_target">
|
||||
@@ -3691,7 +3686,7 @@
|
||||
</value>
|
||||
<value name="train_data">
|
||||
<shadow type="variables_get">
|
||||
<field name="VAR">X_test</field>
|
||||
<field name="VAR">x_test</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
@@ -3717,7 +3712,7 @@
|
||||
</value>
|
||||
<value name="address">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">D:/mixly/test.pkl</field>
|
||||
<field name="TEXT">/test.pkl</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
|
||||
Reference in New Issue
Block a user