Peer to peer loan platforms such as Lending Club and Prosper have established themselves as an important alternative for people who need to acquire credit quickly and at competitive interest rates. Likewise, for lenders it is a way to invest their money expecting higher returns than corporate bonds or a fixed-term certificate of deposit. However, studies have shown that the credit ratings provided by these platforms are those offered by traditional credit bureaus whose scores are made for public banks and not for this new loan scheme. This means that whoever wants to invest in giving loans to people is exposed to a risk that is not calculated correctly. This paper presents a method to create an investment in a portfolio of credits available on P2P platforms based on Machine Learning and Portfolio Optimization. It is shown that the expected return and risk associated with the chosen portfolio can be predicted, giving investors tools to invest according to their risk profile