Package: lightwood
LightwoodLightwood is an AutoML framework that enables you to generate and customize machine learning pipelines declarative syntax called JSON-AI.Our goal is to make the data science/machine learning (DS/ML) life cycle easier by allowing users to focus onwhatthey want to do their data without needing to write repetitive boilerplate code around machine learning and data preparation. Instead, we enable you to focus on the parts of a model that are truly unique and custom.Lightwood works with a variety of data types such as numbers, dates, categories, tags, text, arrays and various multimedia formats. These data types can be combined together to solve complex problems. We also support a time-series mode for problems that have between-row dependencies.Our JSON-AI syntax allows users to change any and all parts of the models Lightwood automatically generates. The syntax outlines the specifics details in each step of the modeling pipeline. Users may override default values (for example, changing the type of a column) or alternatively, entirely replace steps with their own methods (ex: use a random forest model for a predictor). Lightwood creates a "JSON-AI" object from this syntax which can then be used to automatically generate python code to represent your pipeline.For details on how to generate JSON-AI syntax and how Lightwood works, check out theLightwood Philosophy.Lightwood PhilosophyLightwood abstracts the ML pipeline into 3 core steps:(1) Pre-processing and data cleaning(2) Feature engineering(3) Model building and trainingi) Pre-processing and cleaningFor each column in your dataset, Lightwood will identify the suspected data type (numeric, categorical, etc.) via a brief statistical analysis. From this, it will generate a JSON-AI syntax.If the user keeps default behavior, Lightwood will perform a brief pre-processing approach to clean each column according to its identified data type. From there, it will split the data into train/dev/test splits.Thecleanerandsplitterobjects respectively refer to the pre-processing and the data splitting functions.ii) Feature EngineeringData can be converted into features via "encoders". Encoders represent the rules for transforming pre-processed data into a numerical representations that a model can be used.Encoders can berule-basedorlearned. A rule-based encoder transforms data per a specific set of instructions (ex: normalized numerical data) whereas a learned encoder produces a representation of the data after training (ex: a "[CLS]" token in a language model).Encoders are assigned to each column of data based on the data type; users can override this assignment either at the column-based level or at the data-type based level. Encoders inherit from theBaseEncoderclass.iii) Model Building and TrainingWe call a predictive model that intakesencodedfeature data and outputs a prediction for the target of interest amixermodel. Users can either use Lightwood's default mixers or create their own approaches inherited from theBaseMixerclass.We predominantly use PyTorch based approaches, but can support other models.UsageWe invite you to check out ourdocumentationfor specific guidelines and tutorials! Please stay tuned for updates and changes.Quick use casesLightwood works withpandas.DataFrames. Once a DataFrame is loaded, defined a "ProblemDefinition" via a dictionary. The only thing a user needs to specify is the name of the column to predict (via the keytarget).Create a JSON-AI syntax from the commandjson_ai_from_problem. Lightwood can then use this object toautomatically generate python code filling in the steps of the ML pipelineviacode_from_json_ai.You can make aPredictorobject, instantiated with that code viapredictor_from_code.To train aPredictorend-to-end, starting with unprocessed data, users can use thepredictor.learn()command with the data.importpandasaspdfromlightwood.api.high_levelimport(ProblemDefinition,json_ai_from_problem,code_from_json_ai,predictor_from_code,)if__name__=='__main__':# Load a pandas datasetdf=pd.read_csv("https://raw.githubusercontent.com/mindsdb/benchmarks/main/benchmarks/datasets/hdi/data.csv")# Define the prediction task by naming the target columnpdef=ProblemDefinition.from_dict({"target":"Development Index",# column you want to predict})# Generate JSON-AI code to model the problemjson_ai=json_ai_from_problem(df,problem_definition=pdef)# OPTIONAL - see the JSON-AI syntax# print(json_ai.to_json())# Generate python codecode=code_from_json_ai(json_ai)# OPTIONAL - see generated code# print(code)# Create a predictor from python codepredictor=predictor_from_code(code)# Train a model end-to-end from raw data to a finalized predictorpredictor.learn(df)# Make the train/test splits and show predictions for a few examplestest_df=predictor.split(predictor.preprocess(df))["test"]preds=predictor.predict(test_df).iloc[:10]print(preds)BYOM: Bring your own modelsLightwood supports user architectures/approaches so long as you follow the abstractions provided within each step.Ourtutorialsprovide specific use cases for how to introduce customization into your pipeline. Check out "custom cleaner", "custom splitter", "custom explainer", and "custom mixer". Stay tuned for further updates.InstallationYou can install Lightwood as follows:pip3installlightwoodNote: depending on your environment, you might have to use pip instead of pip3 in the above command.However, we recommend creating a python virtual environment.Setting up a dev environmentPython version should be in the range >=3.8, < 3.11Clone lightwoodcd lightwood && pip install -r requirements.txt && pip install -r requirements_image.txtAdd it to your python path (e.g. by addingexport PYTHONPATH='/where/you/cloned/lightwood':$PYTHONPATHas a newline at the end of your~/.bashrcfile)Check that theunittests are passing by going into the directory where you cloned lightwood and running:python -m unittest discover testsIfpythondefault to python2.x on your environment usepython3andpip3insteadCurrently, the preferred environment for working with lightwood is visual studio code, a very popular python IDE. However, any IDE should work. While we don't have guides for those, please feel free to use the following section as a template for VSCode, or to contribute your own tips and tricks to set up other IDEs.Setting up a VSCode environmentInstall and enable setting sync using github account (if you use multiple machines)Install pylance (for types) and make sure to disable pyrightGo toPython > Lint: Enabledand disable everythingbutflake8Setpython.linting.flake8Pathto the full path to flake8 (which flake8)SetPython › Formatting: Providerto autopep8Add--global-config=<path_to>/lightwood/.flake8and--experimentaltoPython › Formatting: Autopep8 ArgsInstall live share and live share whiteboardContribute to LightwoodWe love to receive contributions from the community and hear your opinions! We want to make contributing to Lightwood as easy as it can be.Being part of the core Lightwood team is possible to anyone who is motivated and wants to be part of that journey!Please continue reading this guide if you are interested in helping democratize machine learning.How can you help us?Report a bugImprove documentationSolve an issuePropose new featuresDiscuss feature implementationsSubmit a bug fixTest Lightwood with your own data and let us know how it went!Code contributionsIn general, we follow the"fork-and-pull"git workflow. Here are the steps:Fork the Lightwood repositoryCheckout thestagingbranch, which is the development version that gets released weekly (there can be exceptions, but make sure to ask and confirm with us).Make changes and commit themMake sure that the CI tests pass. You can run the test suite locally withflake8 .to check style andpython -m unittest discover teststo run the automated tests. This doesn't guarantee it will pass remotely since we run on multiple envs, but should work in most cases.Push your local branch to your forkSubmit a pull request from your repo to thestagingbranch ofmindsdb/lightwoodso that we can review your changes. Be sure to merge the latest from staging before making a pull request!Note: You will need to sign a CLI agreement for the code since lightwood is under a GPL license.Feature and Bug reportsWe use GitHub issues to track bugs and features. Report them by opening anew issueand fill out all of the required inputs.Code review processPull request (PR) reviews are done on a regular basis.If your PR does not address a previous issue, please make an issue first.If your change has a chance to affecting performance we will run our private benchmark suite to validate it.Please, make sure you respond to our feedback/questions.CommunityIf you have additional questions or you want to chat with MindsDB core team, you can join our community:.To get updates on Lightwood and MindsDB’s latest announcements, releases, and events, sign up for ourMonthly Community Newsletter.Join our mission of democratizing machine learning and allowing developers to become data scientists!Contributor Code of ConductPlease note that this project is released with aContributor Code of Conduct. By participating in this project, you agree to abide by its terms.Current contributorsLicenseLightwood License