How to delete attribute set by id Magento 2?

You can remove specific attribute set from the system by given id in Magento 2.

If you want to delete extra attribute set from the magento admin panel, You can safely remove it by given id in the deleteById($attributeSetId) from the AttributeSetRepository Interface.

Output will be boolean if attribute set delete successful, true otherwise it will be false.

<?php
namespace Jesadiya\DeleteAttributeSet\Model;

use Exception;
use Magento\Catalog\Api\AttributeSetRepositoryInterface;

class RemoveAttributeSet
{
    /**
     * @var AttributeSetRepositoryInterface
     */
    private $attributeSetRepository;

    public function __construct(
        AttributeSetRepositoryInterface $attributeSetRepository
    ) {
        $this->attributeSetRepository = $attributeSetRepository;
    }

    /**
     * delete attribute set by id
     *
     * @param int $attributeSetId
     * @return boolean
     */
    public function deleteAttributeSet($attributeSetId)
    {
        try {
            $isattributeSetDelete = $this->attributeSetRepository->deleteById($attributeSetId);
        } catch (Exception $exception) {
            throw new Exception($exception->getMessage());
        }

        return $isattributeSetDelete;
    }
}

You can pass attribute set id in the above model class,

$attributeSetId = 5; // id of the attribute set
$attributeSet = $this->deleteAttributeSet($attributeSetId);

Output:
Boolean (True or false)