I'm new in programming Blockchain. I want to make a smart contract with machine learning, a simple case. I know how to create a solidity contract, but I do not know how to add learning to the contract. Does anyone have any ideas?
Machine Learning usually takes a lot of processing power and memory. Blockchain costs a lot for any processing power or memory. I would create smart contracts that do minimal processing and data collection from the blockchain and offload everything CPU and memory intensive via web3, web3j or some other off-chain API to a traditional server.
I'll throw the question back at you. Why would you implement "machine learning" in a smart contract?
The majority of the machine learning models right now have a pipeline that looks like the following:
- Preprocess the data. This operation is unsuitable to do in a smart contract due to the high transaction costs and speed. One could consider adding the final dataset to the blockchain, but there is no benefit from that. Let alone the transaction costs for uploading the data to the blockchain. It would be much more suitable to store it on IPFS if you want free distribution of data that are immutable.
- Train the model: Again it would be crazy to train using a smart contract given the lack of support for linear algebra. Imagine that our local computers run high performant linear algebra libraries in Fortran or C that have been developed and maintained for decades. You could consider storing the model on the blockchain and save other people the effort and the time to train it again.
- Run the model: This depending on the model could be viable, but again the lack of Linear-Algebra libraries would probably make it prohibitively costly to develop.
Take my answer with a grain of salt as the area is developing at a fast pace. Personally, I dont see the reason to use blockchain in machine learning right now. Hopefully, someone smarter than me will come to prove me wrong.
P.S. Check Open Minded that do privacy enhancing decentralized machine learning using differential privacy and secure MPC. However, this is a different beast
You would have to define the smart contracts yourself. While Solidity or Smart Contracts were not meant to used for Machine Learning, here is an interesting incentive for using smart contracts- they let you easily assess the efficiency of a process. But given the fact that we have Python for Machine learning, a language which boast of such a powerful library like Scikit-Learn, one would be hard-pressed to do it.
That being said, Using Solidity and Smart Contracts to test out Machine Learning Concepts isn't a bad idea.