n8n-nodes-clean-data
Version:
A custom n8n node to clean data using Recursive Feature Elimination (RFE) powered by Python.
110 lines • 4.39 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CleanData = void 0;
const child_process_1 = require("child_process");
const util = __importStar(require("util"));
const path = __importStar(require("path"));
const execPromise = util.promisify(child_process_1.exec);
class CleanData {
constructor() {
this.description = {
displayName: 'Clean Data by RFE',
name: 'cleanData',
group: ['transform'],
version: 1,
description: 'Clean data using Recursive Feature Elimination (RFE)',
defaults: {
name: 'Clean Data by RFE',
},
inputs: '={{["main"]}}',
outputs: '={{["main"]}}',
properties: [
{
displayName: 'Target Column',
name: 'targetColumn',
type: 'string',
default: 'target',
description: 'The name of the target column for RFE',
},
{
displayName: 'Number of Features to Keep',
name: 'numFeatures',
type: 'number',
default: 5,
description: 'Number of features to keep after applying RFE',
},
{
displayName: 'Output Format',
name: 'outputFormat',
type: 'options',
options: [
{
name: 'JSON',
value: 'json',
},
{
name: 'Table',
value: 'table',
},
],
default: 'json',
description: 'Choose the output format',
},
],
};
}
async execute() {
const items = this.getInputData();
const targetColumn = this.getNodeParameter('targetColumn', 0);
const numFeatures = this.getNodeParameter('numFeatures', 0);
const outputFormat = this.getNodeParameter('outputFormat', 0);
const data = items[0].json;
const returnData = [];
let outputData = [];
const pythonScriptPath = path.join(__dirname, '../../model/rfe_script.py');
try {
console.log('Data sent to Python script:', data);
const { stdout } = await execPromise(`python "${pythonScriptPath}" "${JSON.stringify(data)}" "${targetColumn}" "${numFeatures}"`);
const cleanedData = JSON.parse(stdout);
if (outputFormat === 'json') {
outputData = [{ json: { cleanedData } }];
}
else {
}
}
catch (error) {
returnData.push({
json: {
error: error.message || 'Error executing RFE script',
stack: error.stack || 'No stack available',
},
});
}
return outputData.length ? [outputData] : [returnData];
}
}
exports.CleanData = CleanData;
//# sourceMappingURL=CleanData.node.js.map