Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to select the modelType and update the valid types prediction array #43

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DataTypeEnum } from '@State/models/constants';
import useFormbit from '@radicalbit/formbit';
import {
createContext,
useContext,
useMemo,
useState,
} from 'react';
import { DataTypeEnum, ModelTypeEnum } from '@State/models/constants';
import schemaStepFour from './step-four/schema';
import schemaStepOne from './step-one/schema';
import schemaStepThree from './step-three/schema';
Expand All @@ -18,7 +18,7 @@ function ModalContextProvider({ children }) {
const [isMaximize, setIsMaximize] = useState(false);

const useFormbitStepOne = useFormbit({
initialValues: { modelType: ModelTypeEnum.BINARY_CLASSIFICATION, dataType: DataTypeEnum.TABULAR },
initialValues: { dataType: DataTypeEnum.TABULAR },
yup: schemaStepOne,
});

Expand Down
13 changes: 10 additions & 3 deletions ui/src/components/modals/add-new-model/step-four/form-fields.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,19 @@ const useGetTargets = () => {
return form.features.filter(({ type }) => targetValidTypes.includes(type));
};

const predictionValidTypes = ['int', 'float', 'double'];
const predictionValidTypes = {
[ModelTypeEnum.BINARY_CLASSIFICATION]: ['int', 'float', 'double'],
[ModelTypeEnum.MULTI_CLASSIFICATION]: ['int', 'float', 'double', 'string'],
[ModelTypeEnum.REGRESSION]: ['int', 'float', 'double'],
};
const useGetPredictions = () => {
const { useFormbit } = useModalContext();
const { useFormbit, useFormbitStepOne } = useModalContext();
const { form } = useFormbit;

return form.outputs.filter(({ type }) => predictionValidTypes.includes(type));
const { form: formStepOne } = useFormbitStepOne;
const { modelType } = formStepOne;

return form.outputs.filter(({ type }) => predictionValidTypes[modelType].includes(type));
};

const binaryClassificationProbabilityValidTypes = ['float', 'double'];
Expand Down
15 changes: 14 additions & 1 deletion ui/src/components/modals/add-new-model/step-one/form-fields.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,22 @@ function Name() {
}

function ModelType() {
const { useFormbit } = useModalContext();
const { form, write } = useFormbit;

const handleOnChange = (value) => {
write('modelType', value);
};

return (
<FormField label="Model type" modifier="w-full" required>
{ModelTypeEnumLabel[ModelTypeEnum.BINARY_CLASSIFICATION]}
<Select onChange={handleOnChange} value={form.modelType}>
{Object.values(ModelTypeEnum).map((value) => (
<Select.Option key={value}>
{ModelTypeEnumLabel[value]}
</Select.Option>
))}
</Select>
</FormField>
);
}
Expand Down
Loading